logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 06-30-2007, 08:46 PM   #1
mr_badger
 
Join Date: Dec 2006
Posts: 84
Default

I have done the dropdown menu tutorial and I'am getting this message
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

heres my code.
Code:
<?php
require_once('Connections/conn.php');

$make    =    $_POST['make'];


if ($make){
/////////////////////////////////////////////////
$query        = sprintf("SELECT * FROM car_model where car_model_id='$make'");
$result     = @mysql_query($query); 
$rowModel     = mysql_fetch_array($result);
/////////////////////////////////////////////////
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="dropdown.php" >

  <select name="make" onChange="document.forms[0].submit()">
      <option value="">Select Make</option>
      <option value="1" <?php if(!(strcmp(1, $make))){echo "selected";}?>>Alfa Romeo</option>
    <option value="2" <?php if(!(strcmp(2, $make))){echo "selected";}?>>Audi</option>
    <option value="3" <?php if(!(strcmp(3, $make))){echo "selected";}?>>BMW</option>
    <option value="4" <?php if(!(strcmp(4, $make))){echo "selected";}?>>Citroen</option>
  </select>
 

  <select name="model">
    <option value="">Select Model</option>
    <?php do {  ?>
    <option value="<?php echo $rowModel['car_model_id']; ?>"><?php echo $rowModel['car_model']; ?></option>
    <?php  }while ($rowModel = mysql_fetch_array($result));  ?>
  </select>
  
</form>
</body>
</html>
mr_badger is offline   Reply With Quote
Old 06-30-2007, 09:37 PM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

thats correct

its a warning which is displaying correctly. Just stick an @ infront of the function to supress it

PHP Code:
@mysql_fetch_array(): 
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 07-01-2007, 03:59 PM   #3
mr_badger
 
Join Date: Dec 2006
Posts: 84
Default

ok I have done that and there is no error message but I'am not getting any data in the second dropdown when I choose from the first drop down?
mr_badger is offline   Reply With Quote
Old 07-01-2007, 04:42 PM   #4
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

where you have

PHP Code:
/////////////////////////////////////////////////
$query        sprintf("SELECT * FROM car_model where car_model_id='$make'");
$result     = @mysql_query($query); 
$rowModel     mysql_fetch_array($result);
///////////////////////////////////////////////// 
add an echo like this...
PHP Code:
 
/////////////////////////////////////////////////
echo $query        sprintf("SELECT * FROM car_model where car_model_id='$make'");
$result     = @mysql_query($query); 
$rowModel     mysql_fetch_array($result);
///////////////////////////////////////////////// 
try selecting the dropdown then post the resulting message to the screen
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 07-01-2007, 11:12 PM   #5
mr_badger
 
Join Date: Dec 2006
Posts: 84
Default

now when I select a make I get this message, SELECT * FROM car_model where car_model_id='3

Nothing in the second dropdown.
mr_badger is offline   Reply With Quote
Old 07-02-2007, 05:33 AM   #6
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

ok thats fine. You are passing in an ID correctly. Does that ID exist in the db?
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 07-02-2007, 10:08 AM   #7
mr_badger
 
Join Date: Dec 2006
Posts: 84
Default

Yes that id does exsist in the database, but could it be to do with NULL and NOT NULL in the database because I have 'make' in the car make table as NULL and both 'car_Model_id' and 'car_model' in the car model table as NULL.
mr_badger is offline   Reply With Quote
Old 07-02-2007, 02:10 PM   #8
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

do you have a value in the tables

2 tables both with data and both have a relationship id
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 07-02-2007, 08:42 PM   #9
mr_badger
 
Join Date: Dec 2006
Posts: 84
Default

yes I have all that.
mr_badger is offline   Reply With Quote
Old 07-03-2007, 05:42 AM   #10
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

i cant see any problem with the code

if you echo...

PHP Code:
echo $rowModel['car_model_id']; 
do you see any results
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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

Forum Jump


All times are GMT. The time now is 03:56 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com