Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-16-2005, 10:23 AM Php Option Dropdown
Experienced Talker

Posts: 35
Trades: 0
Hi Guys,

I’m a bit stuck working on a PHP content management system that assigns a photograph with each profile I create.

Now I have my php page set-up so you can enter a variable called $firstname, and this data entered into the textbox is saved in MySQL database in a table called ‘profiles’ when you hit submit - (and it can be retrieved and modified) as shown below:

PHP Code:

<?php

// login stuff

include("../ch.php");
include(
"../cm.php");
checklogin();

$firstname "";
$image "";

if(isset(
$_POST['Submit']))
{

    
$firstname $_POST['firstname'];
    
$image $_POST['image'];
    
    if(!isset(
$_GET['profilesid']))
    {
        
$result mysql_query("Insert into profiles(firstname,image) values('$firstname','$image')");
        
$msg "New record is saved";
    }
    else
    {
        
$result mysql_query("Update profiles set firstname='$firstname', image='$image' where profilesid=".$_GET['profilesid']);
        
$msg "profiles Record is updated";
    }
}
if(isset(
$_GET['profilesid']))
{
    
$result mysql_query("Select * From profiles where profilesid=".$_GET['profilesid'],$link);
    
$row mysql_fetch_array($resultMYSQL_BOTH);
    
$firstname $row['firstname'];
    
$image $row['image'];
}
?>
<html>
<head>
<title>Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../ssheet.css">
</head>

<body>
<div align="center"></div>
<form name="form1" method="post" action="">
  <input name="firstname" type="text" id="firstname" value="<?php echo $firstname?>" size="36">
</form>
</body>
</html>
Now as you can see I also have an $image variable on this page. What I want to do is create an <option></option> drop down menu, which looks at a different table in MySQL database called ‘uploads’ which holds information on .jpg images uploaded to a folder.

Basically each .jpg uploaded has $name and $url data assigned to it in the ‘uploads’ table..

So I want the <option></option> drop down menu to do is:

- Return all $name of uploaded images in the dropdown
- Hit Submit
- The $URL to that image I have selected is held in the ‘profiles’ table
held in the $image variable.

But I have not got a clue how to do it – anybody help?

Thanks

Chris
chrisb is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-16-2005, 10:29 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
1. select all image names from uploads
2. in a while create an option for each one. putting the name as value
3. the select will return the name of the image afetr submission.
4. select url from uploads where name = value returned by select
5. update profile with the url returned.

i think this would be one way of doing it....
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-16-2005, 10:36 AM
Experienced Talker

Posts: 35
Trades: 0
Thanks - but i'm very new to this. Any chance of some code/

I tried the below:

PHP Code:

<select name="image"> 
<option value="" selected>select an image...</option> 
<?php 
$query 
mysql_query("SELECT * FROM `uploads`"); 
while(
$image mysql_fetch_assoc($query)){ 
?> 
<option value="<?php echo $image['url']; ?>"><?php echo $image['name']; ?></option> 
<?php 

?> 
</select>
A while back, which selected the image name, but did not save the $image information in the $image url information in my 'profiles' table?

Any ideads?
chrisb is offline
Reply With Quote
View Public Profile
 
Old 05-16-2005, 10:47 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
that part of code seems corect, i don't know why you add <option value="" selected>select an image...</option>, you can just add it as text before the select box and you woun't have to make sure they don't select it.


any way, back to the problem:
i see you have no submit button, how are you submitting it?

anyway, here is some code you can use as inspiration since i really must leave soon.
PHP Code:
<form name="st_stud" method="post" action="index.php?pagina=cont">
  <select name="idpr">
<?
    $query 
mysql_query("SELECT `username`, `id_user` FROM `dor_useri` WHERE `tip` = 1");
    while (
$row mysql_fetch_array($queryMYSQL_ASSOC)) {
?>
      <option value="<? echo $row['id_user']; ?>"><? echo $row['username']; ?></option>
<?
    
}
?>
  </select>
  <input type="submit" name="stergepr" value="sterge cont profesor">
</form>
PHP Code:
if (isset($_POST['stergepr'])) {
    
$user $_POST['idpr'];
    echo 
$user;

the $user in the last part will be your image.

than you do an sql update with it.

SELECT url FROM update WHERE name = $user (your image)

than UPDATE profiles .... with the url.
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-16-2005, 11:18 AM
Experienced Talker

Posts: 35
Trades: 0
Thanks OmuCuSucu,

Your code seems to have gone over my head for a novice like me, but you seemed to indicate i'm nearly there with:

PHP Code:
<select name="image"> 
<option value="" selected>select an image...</option> 
<?php 
$query 
mysql_query("SELECT * FROM `uploads`"); 
while(
$image mysql_fetch_assoc($query)){ 
?> 
<option value="<?php echo $image['url']; ?>"><?php echo $image['name']; ?></option> 
<?php 

?> 
</select>
This code i've posted. Therefore can anyone please suggest where i'm wrong?

Thanks
chrisb is offline
Reply With Quote
View Public Profile
 
Old 05-16-2005, 11:30 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
hey, what is the structure of the profiles table?

EDIT:
PHP Code:

<form name="form" method="post" action="">
  <select name="image">
<?
    $query 
mysql_query("SELECT * FROM uploads");
    while (
$image mysql_fetch_assoc($query)) {
?>
      <option value="<?php echo $image['name']; ?>"><?php echo $image['name']; ?></option> 
<?
    
}
?>
  </select>
  <input type="submit" name="select" value="select">
</form> 
<?
if (isset($_POST['select'])) {
    
$imagename $_POST['image'];
    
$query mysql_query("UPDATE profiles SET imageurl = (SELECT url FROM upload WHERE name = $imagename) WHERE [[[[ set condition to identify user here. ]]]]");
}
?>
i made this, but didn't get to test it ... tell me if you don't uderstand something
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.

Last edited by OmuCuSucu; 05-16-2005 at 11:34 AM..
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Php Option Dropdown
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33067 seconds with 12 queries