PDA

View Full Version : Problems loading table with "do" loop


AMMoyer
05-07-2008, 07:40 PM
OK, I've been through the Beginning PHP Tutorials several times now. I'm having trouble getting my query info loaded into an HTML table. I've used a do loop after the query to show the data and all's well. When I comment out that do loop and put the same statements around my <tr> statements I get Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource. If I leave all loops out I only get the first row of info in the table. Thanks for any input.

Adam



<?php
if ($model){
/////////////////////////////////////////////////
$query3 = sprintf("SELECT partterminologyname, position, mfgpart, notes FROM chassis WHERE make='$make' AND model='$model' AND year<='$year' AND yearto>='$year'");
$result3 = @mysql_query($query3);
$rowAll = mysql_fetch_array($result3);
/////////////////////////////////////////////////
///do {
///echo $rowAll['mfgpart'], $rowAll['partterminologyname'], $rowAll['position'], $rowAll['notes']."<br>";
///} while ($rowAll = mysql_fetch_array($result3))
}
?>

<table width="800" border="0">
<tr>
<td width="100"><div align="center">Ingalls Part #</div></td>
<td width="260"><div align="center">Part Name</div></td>
<td width="188"><div align="center">Location</div></td>
<td width="220"><div align="center">Notes</div></td>
</tr>
<?php do{ ?>
<tr>
<td><?php echo $rowAll['mfgpart'];?></td>
<td><?php echo $rowAll['partterminologyname'];?></td>
<td><?php echo $rowAll['position'];?></td>
<td><?php echo $rowAll['notes'];?></td>
</tr>
<?php } while ($rowAll = mysql_fetch_array($result3)); ?>
</table>

lux
05-08-2008, 10:29 AM
comment out this line:

$rowAll = mysql_fetch_array($result3);

AMMoyer
05-08-2008, 02:51 PM
So I left the argument out;

<?php } while() ;?>

And still get the same error. I've tried a "while" loop instead of the "do-while" and get the same error with the argument. The same argument works on this page to load a drop down menu. Are there any other avenues that I should persue??

m1a2x3x7
05-08-2008, 04:46 PM
Can you post all your code?

AMMoyer
05-08-2008, 05:08 PM
Here ya go. It works now, but I get the 'mysql_fetch_array ():supplied arguement is not a valid mysql result resource' when the page loads but it disappears after my dropdown boxes are filled and my table is populated. The line the error references is the 'while' line of the table data loading loop. Sorry lux, I first commented out the incorrect line, but your suggestion did get me closer.


<?php
require_once("Connections/dbconfig.php"); // database connnection
$year = $_POST['year2'];
$make = $_POST['make'];
$model = $_POST['model'];
if ($year){
///////////////////////////////////////////////// make query for dropdown
$query = sprintf("SELECT DISTINCT makeid, makename FROM iemmy WHERE yearid='$year'");
$result = @mysql_query($query);
$rowMake = mysql_fetch_array($result);
/////////////////////////////////////////////////
}
if ($make){
///////////////////////////////////////////////// model query for dropdown
$query2 = sprintf("SELECT modelid, modelname FROM iemmy WHERE makeid='$make' AND yearid='$year'");
$result2 = @mysql_query($query2);
$rowModel = mysql_fetch_array($result2);
/////////////////////////////////////////////////
}
if ($model){
///////////////////////////////////////////////// part query for table
$query3 = sprintf("SELECT partterminologyname, position, mfgpart, notes FROM chassis WHERE make='$make' AND model='$model' AND year<='$year' AND yearto>='$year'");
$result3 = @mysql_query($query3);
///$rowAll = mysql_fetch_array($result3);
/////////////////////////////////////////////////
///do {
///echo $rowAll['mfgpart'], $rowAll['partterminologyname'], $rowAll['position'], $rowAll['notes']."<br>";
///} while ($rowAll = mysql_fetch_array($result3))
}
?>
<!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="year2" onchange="document.forms[0].submit()">
<option value="" selected="selected">Select Year</option>
<option value="2009" <?PHP if (!(strcmp(2009, $year))){echo "selected";}?>>2009</option>
<option value="2008" <?PHP if (!(strcmp(2008, $year))){echo "selected";}?>>2008</option>
<option value="2007" <?PHP if (!(strcmp(2007, $year))){echo "selected";}?>>2007</option>
<option value="2006" <?PHP if (!(strcmp(2006, $year))){echo "selected";}?>>2006</option>
<option value="2005" <?PHP if (!(strcmp(2005, $year))){echo "selected";}?>>2005</option>
<option value="2004" <?PHP if (!(strcmp(2004, $year))){echo "selected";}?>>2004</option>
<option value="2003" <?PHP if (!(strcmp(2003, $year))){echo "selected";}?>>2003</option>
<option value="2002" <?PHP if (!(strcmp(2002, $year))){echo "selected";}?>>2002</option>
<option value="2001" <?PHP if (!(strcmp(2001, $year))){echo "selected";}?>>2001</option>
<option value="2000" <?PHP if (!(strcmp(2000, $year))){echo "selected";}?>>2000</option>
</select>
<select name="make" onchange="document.forms[0].submit()">
<option value="">Select Make</option>
<?php do { ?>
<option value="<?php echo $rowMake['makeid']; ?>"<?PHP if (!(strcmp($rowMake['makeid'], $make))){echo "selected";}?>><?php echo $rowMake['makename']; ?></option>
<?php }while ($rowMake = mysql_fetch_array($result)); ?>
</select>
<select name="model" onchange="document.forms[0].submit()">
<option value="">Select Model</option>
<?php do { ?>
<option value="<?php echo $rowModel['modelid']; ?>"<?PHP if (!(strcmp($rowModel['modelid'], $model))){echo "selected";}?>><?php echo $rowModel['modelname']; ?></option>
<?php }while ($rowModel = mysql_fetch_array($result2)); ?>
</select>
</form>
<table width="800" border="0">
<tr>
<td width="100" bgcolor="#CCCCCC"><div align="center">Ingalls Part #</div></td>
<td width="260" bgcolor="#CCCCCC"><div align="center">Part Name</div></td>
<td width="188" bgcolor="#CCCCCC"><div align="center">Location</div></td>
<td width="220" bgcolor="#CCCCCC"><div align="center">Notes</div></td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $rowAll['mfgpart'];?></td>
<td><?php echo $rowAll['partterminologyname'];?></td>
<td><?php echo $rowAll['position'];?></td>
<td><?php echo $rowAll['notes'];?></td>
</tr>
<?php }while ($rowAll = mysql_fetch_array($result3)); ?>
</table>
</body>
</html>

davidj
05-09-2008, 05:47 AM
add an @ to the following line


$rowMake = @mysql_fetch_array($result);///<< note the @