Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199908

[PHP3] PHP/Mysql - Working with Arrays From: Yoed Anis (yoed <email protected>)
Date: 08/23/99

Hello!

Ok well basically what I want to do is run a for loop from a Mysql array. Where each time throughout the loop would run through a different element orderly.

Now I looked up manuals, web pages, books.. the like for about a week now and tried many different things.
The best thing I've come up with looks like:

<?
....
mysql_select_db( "Cart" );
$queryResult1=mysql_query("SELECT Category FROM CartItems");
$correspondingRowArray = mysql_fetch_row( $queryResult1 );

echo "<FORM ACTION='shipping.phtml' METHOD='POST' ENCTYPE='application/x-www-form-urlencoded'>";
echo "<BR>";
echo "<table border='1' cellpadding='5' cellspacing='5'>";
echo "<tr>";

for ($correspondingRowArraySize = sizeof( $correspondingRowArray ); $content = current( $correspondingRowArray ); $contentnext = next( $correspondingRowArray )) {

$result=mysql_query("SELECT * FROM Category WHERE Category='$content' ORDER BY Category");
$row = mysql_fetch_row($result) ;
$Category=$row[0];
$Shipname0=$row[1];
$Shipping0=$row[2];
$Shipname1=$row[3];
$Shipping1=$row[4];
$Shipname2=$row[5];
$Shipping2=$row[6];

echo "<th>";

blueFont("Arial","Select Shipping Method for $content:");
echo "<BR>";

echo "<select name='ShippingMethod' size='3'>";
echo "<option value='$Shipping0'>$Shipping0 - $Shipname0</option>";
echo "<option value='$Shipping1'>$Shipping1 - $Shipname1</option>";
echo "<option value='$Shipping2'>$Shipping2 - $Shipname2</option>";

echo "</select>";
echo "<input type='hidden' name='Ca' value='$Ca'>";
echo "<input type='hidden' name='Ship0' value='$Shipping0'>";
echo "<input type='hidden' name='Ship1' value='$Shipping1'>";
echo "<input type='hidden' name='Ship2' value='$Shipping2'>";

echo "<br>";
echo "</th>";
echo "</tr>";
}
echo "<tr>";
echo "<th>";
echo "<input type='Submit' name='submit' value='Ship!'>";
echo "</th>";
echo "</tr>";
echo "</form>";
echo "</table>";

?>

OK so from the example above you will notice I am trying to get different shipping options listed for each Category.
Now this script works ok when I have only one category in the table (CartItems), but for some strange reason when I have more rows listed that have a different category the loop only displays one!
When I echo "$correspondingRowArraySize"; It tells me the array size is 1.... But I have more rows?

So what am I doing wrong here? How else can I get an array build from Mysql that will allow more then 1 elements? :-)

Also, I was sort of wondering if there is a nice method of how to limit the categories I call up (like so the same category won't be displayed twice?).

Thanks a bunch you guys for the help in advance!
Yoed
Halifax, Canada
yoed <email protected>