Web Hosting Talk







View Full Version : No value for $row["cat_".$id] in PHP


blunder
04-20-2007, 05:22 PM
I have a form, where I display a number of different radio buttons based on the data in a table. The problem is however when I want to redisplay the form and I just cant figure it out. I already start having problems when i want to run through the information and check if it is ok. How the heck :)

The form input comes from the form named "cat_$id", where $id is a number from 1 to 40. How do I then collect the data being sent as POST?

$sqltext = "SELECT id FROM cats WHERE type='".$postarray["type"]."' ORDER BY name";
$result = mysql_query($sqltext);
$i = 0;
while ($row = mysql_fetch_array($result)) {
$id = $row["id"];
if ($cat_.$id == 1) {
$postarray["cat_".$id] = 1;
$i++;
}
}

Anyone able to help or point me in the right direction?

horizon
04-20-2007, 05:52 PM
Let's try out this approach:


$sqltext = "SELECT id FROM cats WHERE type='".$postarray["type"]."' ORDER BY name";
$result = mysql_query($sqltext);
$i = 0;
while ($row = mysql_fetch_array($result)) {
$id = $row["id"];
$i++;
} // End while.

$ids = array();

foreach ($id as $key => $val) {
if (is_numeric($val) && intval($val)) {
$ids[$postarray['cat_'.$val]] = 1;
} // End if.
} // End foreach.


;)

blunder
04-20-2007, 06:08 PM
Maybe I am misunderstanding, but this doesnt quite solve things. I need to check if the form posted data to $cat_10 (for example) is set to 1 or not.

In the form I have a while() that runs through the rows of the $result and outputs a radio button for each id with the name.

Would this truly check the data from the post?

ThatScriptGuy
04-20-2007, 09:46 PM
You do see in your if-statement that you have a $ before cat, right? The way the rest of your code looks, I'm thinking that 'cat_' is a constant name, with '$id' being changed...

if ($cat_.$id == 1)

Badie
04-23-2007, 01:14 AM
first you need to be sure that query bring some data , try to hem and haw the problem place ,used static values and echo, and be sure that you variables names are fine (case sensitive).