The silly me, I had an exit; inside the for loop and I was wondering why
id only looped once, somebody slap me!
- Victor > www.argilent.com
-Original Message-
From: Victor [mailto:[EMAIL PROTECTED]]
Sent: Saturday, August 31, 2002 7:52 AM
To: [EMAIL PROTECTED]
Subject: [PHP] calling sql results inoto variables
I'm trying to go about doing this:
While there is data in an array, get and echo individual pieces from
this array and execute a mysql query that gets the other info in the
table where arraypiece. Stop when all arraypice have been echoed.
The array gets its values from and checkbox form. I got that part:
So I count the number of times there is something in $check, which I
think is done like so:
for($i = 0; $i < sizeof($check); $i++) {
echo $i;
}
that should give me the number of checboxes clicked. (it does, I
verified)
so, now I say:
for($i = 0; $i < sizeof($check); $i++) {
# echo $i;
echo '';
$data = $check[$i];
echo $data;
which brings me to getting the rest of the data from the tables (the
array I was talking about holds the ID) (aka the key) but I still need
to put the key in the door.
Ok, so no I would need to loop a mysql query for as long as there is
data in the array, - since I only have one key for each row.
Let me try to write it:
for($i = 0; $i < sizeof($check); $i++) {
# echo $i;
echo '';
$data = $check[$i];
#echo $data;
mysql_query("SELECT * FROM table WHERE ID = '$data'");
$db_ID = $row["ID"];
$db_picture_name = $row["picture_name"];
echo $db_ID;
echo $db_picture_name;
}
Now, this should do the trick, let's test it ... testing ...
Nope, mysql can't execute that query...
Hmmm...
I get this
could not execute queryYou have an error in your SQL syntax near 'table
WHERE ID = '1'' at line 1
no shit! I actually don't have a table called table!
Fixed that, testing
could not execute queryNo Database Selected
ok, let's do that. (I've been up all nigh what do you want!)
ok, now what?!
I get NOTHING! NOTHING! WHHHT!
I tried hardcoding the $ID, nothing, so that must be ok, as we have
proved earlier,
By this time I ended up with this code:
for($i = 0; $i < sizeof($check); $i++) {
# echo $i;
echo '';
$data = $check[$i];
#echo $data;
mysql_query("SELECT * FROM kodak_user_pictures WHERE ID = '1'")
or die ('could not execute query '.mysql_error());
$db_ID = $row["ID"];
$db_picture_name = $row["picture_name"];
echo $db_ID;
echo $db_picture_name;
}
of course it gives me nothing!
What the hell is $row?
Ok, let's fix that.
for($i = 0; $i < sizeof($check); $i++) {
# echo $i;
echo '';
$data = $check[$i];
#echo $data;
$db_data = mysql_query("SELECT * FROM kodak_user_pictures WHERE ID =
'1'");
$row = mysql_fetch_array(db_data);
$db_ID = $row["ID"];
$db_picture_name = $row["picture_name"];
echo $db_ID;
echo $db_picture_name;
}
now I get this... I'm also getting tired...
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource
STUPID $ SIGN! (look near db_data, nope, the second one!)
Ok, let's test ...
Ok, good, let's switch the hardcoded 1 from the query back to the
$data...
Testing ...
Ok, now it only gets one...
Let's try a for each
for($i = 0; $i < sizeof($check); $i++) {
# echo $i;
echo '';
$data = $check[$i];
#echo $data;
foreach ($data as $check[$i]) {
$db_data = mysql_query("SELECT * FROM kodak_user_pictures WHERE ID =
'$data'");
$row = mysql_fetch_array($db_data);
$db_ID = $row["ID"];
$db_picture_name = $row["picture_name"];
echo $db_ID;
echo $db_picture_name;
}
}
Warning: Invalid argument supplied for foreach()
Ok...
Not better, but let's see...
Ok, now I ende up with this code:
for($i = 0; $i < sizeof($check); $i++) {
# echo $i;
echo '';
$data = $check[$i];
$db_data = ("SELECT * FROM mytable WHERE ID = '$check[$i]'");
$row = mysql_query($db_data);
# $row = mysql_fetch_array($db_data);
$db_ID = $row["ID"];
$db_picture_name = $row["picture_name"];
echo $db_ID;
echo $db_picture_name;
#echo $data;
}
I don';t know what to do, I get nothing, I think the error is that I do
not know how to call the mysql query results into the variables fro
echoing, please I beg you someone tell me.
- Victor > www.argilent.com
__
Post your free ad now! http://personals.yahoo.ca
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
__
Post your free ad now! http://personals.yahoo.ca
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php