so i have this code on 3 different pages... and i'm kinda a newb... can u please help. the script is suppose to let someone select a $manufacturer... then from there select a $model... and then finally see the $notes for that model. The script works until it gets to the $notes. it shows the notes for all the $manufacturers $models and not just the selected $model. Here is the codes from the 3 pages:
index.php

mysql_select_db("next2new_phone_notes", $mysql_access);
$result = mysql_query("SHOW tables", $mysql_access);
  while($manufacturer = mysql_fetch_row($result))
  
      echo"<a href=see_phones.php?manufacturer=$manufacturer[0]>$manufacturer[0]</a><br>";

see_phones.php

mysql_select_db("next2new_phone_notes", $mysql_access);
$result = mysql_query("SELECT DISTINCT model FROM $manufacturer ORDER BY id DESC", $mysql_access);
  while($model = mysql_fetch_row($result))
  
      echo"<a href=phone_notes.php?manufacturer=$manufacturer&?model=$model[0]>$model[0]</a><br>";

phone_notes.php

mysql_select_db("next2new_phone_notes", $mysql_access);
$result = mysql_query("SELECT note FROM $manufacturer WHERE model=\"$model\"", $mysql_access);
  while($note = mysql_fetch_row($result))
  echo"$note[0]<hr>";

so i have this code on 3 different pages... and i'm kinda a newb... can u please help. the script is suppose to let someone select a $manufacturer... then from there select a $model... and then finally see the $notes for that model. The script works until it gets to the $notes. it shows the notes for all the $manufacturers $models and not just the selected $model. Here is the codes from the 3 pages:
...
see_phones.php

mysql_select_db("next2new_phone_notes", $mysql_access);
$result = mysql_query("SELECT DISTINCT model FROM $manufacturer ORDER BY id DESC", $mysql_access);
  while($model = mysql_fetch_row($result))
  
      echo"<a href=phone_notes.php?manufacturer=$manufacturer&?model=$model[0]>$model[0]</a><br>";

I think that just this one line is your problem. For HTTP, you don't include the ? for additional parameters. This line should be ... ?manufacturer=$manufacturer&model=$model... The extra ? is what's messing you up. It also wouldn't hurt to quote your href, so the final line would be something like:

echo"<a href=\"phone_notes.php?manufacturer=$manufacturer&model=$model[0]\">$model[0]</a><br>";

For future reference, you can always dump the $_GET array to see if you're actually getting the parameters you think you're getting. To debug you could have done something like this on phone_notes.php.

print_r($_GET);

Holler back if that doesn't solve your problem. I'm still not entirely sure why the SQL line for model="" (assuming $model is not set) is returning all entries instead of no entries.

-geis

Thanks for your response... it was a complete newb error on my part... fixed though with the help of someone on another forum.

I changed the code on see_phones.php to: echo"<a href=phone_notes.php?manufacturer=$manufacturer&amp;model={$model[0]}>$model[0]</a><br>"; then I changed phone_notes.php to: $result = mysql_query("SELECT note FROM $manufacturer WHERE model='$model'", $mysql_access);

That makes sense, glad you got it solved. I've found a lot of browsers will fix errors like a missing &amp; which sometimes can make it harder to debug on a particular browser, etc.

Long term, you might consider creating a table for models and assigning each model a unique id (primary key), which you could then use to reference your data.

Glad it's up and working!

I have a new problem with this script... say the user names the $model=samsung instinct... when it goes to retrieve the $model the script will stop at $model=samsung

Because there is a space it will not grab the whole name from the database. is there any way around that?

Thanks in advance!

Could you be a little more specific? From what you describe, I can't tell if the problem is from the DB extraction (probably not) or from the way you are constructing links (more likely).

For starters though, you could always run the query manually and see if the db is kicking back what you'd expect...

sure... when the user gets to see_phones.php ever thing is fine and it shows a link for:

ax 260 scooplx 260 rumor

when i click on it to go to phone_notes.php it goes to:

phone_notes.php?manufacturer=LG&model=ax

but it should go to

phone_notes.php?manufacturer=LG&model=ax 260 scooplx 260 rumor

Ok, that should be easy enough. The reason for that is that spaces aren't valid for http URLs, so you're going to need to encode the URL first. Before you output that value inside of the <a href, run it through one of the php encode operations:

$linkref = rawurlencode($linkref);

That should solve your problem. Let us know how it goes.

-geis

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.