Click to See Complete Forum and Search --> : putting a database record into a variable


hammerslane
12-15-2003, 04:00 AM
hey folks.
this question is mainly to do with mysql syntax, all help /slight feedback is appreciated

i'm basically trying to delete a chosen record from a database.
there's a while loop on index.php which shows all records in a table.
in the while loop, below every row of data, there's a DELETE and EDIT option like this:
Job Title job1
Pay Rate pay1
Shift Pattern shift1
Qualifications qual1
Location loca1
Description des1
edit | delete

Job Title job2
Pay Rate pay2
Shift Pattern shift2
Qualifications qual2
Location loc2
Description desc2
edit | delete

etc, etc

when you click delete, it should go to another page and display that particular record and ask for a confirmation for the delete
the thing is, i want to pass the $jobtitle variable (with the value of 'job2' for example), over to the next page.

i thought that defining the variable at the beginning of the while loop would work, like this,$jobtitle=$row["jobtitle"];for all the variables, so that i'd have all the relevant variables defined, so i could use them in the WHERE jobtitle='$jobtitle' in the sql statement on the final delete page.

the problem is, i can't figure out how to get the variable defined.
is $jobtitle=$row["jobtitle"]; the right way to define a variable with database info?

i don't know if i'm doing this the right way, so any comments/slaps are more than welcome :cool:

thanks

Khalid Ali
12-15-2003, 06:41 AM
your declaration looks good to me(since you have not provided us with code segment where you are actually geting reference to each row)

It entirely depends on your logic how you want to do it though,
I'd probably use sessions in php to get a value set and then retrieve that value on any other page..

some one may find using URL for data forwarding easy...hence its your own choice the way you want to do it

pnaj
12-15-2003, 07:01 AM
I assume your while loop looks something like ...

$sql = 'SELECT field1, field2, ... FROM ...';
$res = mysql_query($sql);
while($var = mysql_fetch_XXX($res)){
// Print stuff
}

It depends on which of the mysql 'fetch' functions you use:
mysql_fetch_row returns a straightforward array:
then, above $var[0] returns field1, $var[1] returns field2, etc.

mysql_fetch_array returns a 'hash' array:
then, above $var['field1'] returns field1, $var['field2'] returns field2, etc.

mysql_fetch_object returns an object:
then, above $var->field1 returns field1, $var->field2 returns field2, etc.

Hope that makes sense.

hammerslane
12-15-2003, 08:21 AM
thanks for the replies guys - still nothing, but i'll keep messing about with the code... sometimes works...
:( :rolleyes:

pnaj
12-15-2003, 08:31 AM
If you want, show us the bit of code that causing problems.

hammerslane
12-15-2003, 08:40 AM
i managed to get it working - i was trying to define the variables outside of the while ($row = mysql_fetch_array($result)) :....... ever felt really stupid?

i was going to try and give you all the code which i was working on, but it would have taken 5 hours to read it, because of so many random formatting tags.

thanks guys