deanshelton1334
Aug 21st 2007, 3:00 pm
im having issues with this little chunk of PHP code...:confused:
This set of code pulls product data from the mySQL database. each product has basic stuff (name, price, brand, model number, etc...) and most importantly a 'row' called "itemcompad" which includes item numbers of other products it is compatible with.
because i can not anticipate EVERY brand name we may eventually carry... when the user clicks on an item to see what it is compatible with.. i have to explode the commas in "itemcompad " and search each item number's BRAND & attach it to its appropriate array and display it after its all neatly packed away...
If i get any feedback it would be appreciated...any serious questions will be responded to quickly.
Thanks!
//find all possible brands
$sql="SELECT DISTINCT itembrand FROM Products ORDER BY itembrand ASC";
$result= mysql_query($sql) or die(mysql_error());
$numrows=mysql_num_rows(mysql_query($sql));
echo "possible:$numrows";
while(($brandrow = mysql_fetch_array($result))&&($x<$numrows)) {
$unibrand=$brandrow['itembrand'];
//check the displayed items' itemcompad row for ALL brand names and assign them to a unique brand array
$sql="SELECT * FROM Products where itemnumber='$itemnumber'";
$result= mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result)){
$compad = explode(',',$row['itemcompad']);
foreach($compad as $itemquery){
$query = "SELECT * FROM Products WHERE itemnumber ='$itemquery'";
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_fetch_array($result);
$q_itembrand=$rows['itembrand'];
$q_itemnumber=$rows['itemnumber'];
$q_itemmodel= $rows['itemmodelnumber'];
//check for items in the history with the same brand name as the array, and store with other pertnant information.
if($q_itembrand==$unibrand){$combodata[]="$q_itemnumber#$q_itembrand#$q_itemmodel";}
//done! items stored in array. now blow it back up and display it...
$datachunks = explode('#',$combodata);
$datachuncks[1]=$chunck_itemnumber;
$datachuncks[2]=$chunck_itembrand;
$datachuncks[3]=$chunck_itemmodel;
echo"<tr><td> $unibrand:"; if($chunck_itembrand == $unibrand){echo "compad with:$chunck_itemmodel";
}}}}}
WHY WONT THIS WORK!? Please.. Thank you for any Help.. be kind, im New!
This set of code pulls product data from the mySQL database. each product has basic stuff (name, price, brand, model number, etc...) and most importantly a 'row' called "itemcompad" which includes item numbers of other products it is compatible with.
because i can not anticipate EVERY brand name we may eventually carry... when the user clicks on an item to see what it is compatible with.. i have to explode the commas in "itemcompad " and search each item number's BRAND & attach it to its appropriate array and display it after its all neatly packed away...
If i get any feedback it would be appreciated...any serious questions will be responded to quickly.
Thanks!
//find all possible brands
$sql="SELECT DISTINCT itembrand FROM Products ORDER BY itembrand ASC";
$result= mysql_query($sql) or die(mysql_error());
$numrows=mysql_num_rows(mysql_query($sql));
echo "possible:$numrows";
while(($brandrow = mysql_fetch_array($result))&&($x<$numrows)) {
$unibrand=$brandrow['itembrand'];
//check the displayed items' itemcompad row for ALL brand names and assign them to a unique brand array
$sql="SELECT * FROM Products where itemnumber='$itemnumber'";
$result= mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result)){
$compad = explode(',',$row['itemcompad']);
foreach($compad as $itemquery){
$query = "SELECT * FROM Products WHERE itemnumber ='$itemquery'";
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_fetch_array($result);
$q_itembrand=$rows['itembrand'];
$q_itemnumber=$rows['itemnumber'];
$q_itemmodel= $rows['itemmodelnumber'];
//check for items in the history with the same brand name as the array, and store with other pertnant information.
if($q_itembrand==$unibrand){$combodata[]="$q_itemnumber#$q_itembrand#$q_itemmodel";}
//done! items stored in array. now blow it back up and display it...
$datachunks = explode('#',$combodata);
$datachuncks[1]=$chunck_itemnumber;
$datachuncks[2]=$chunck_itembrand;
$datachuncks[3]=$chunck_itemmodel;
echo"<tr><td> $unibrand:"; if($chunck_itembrand == $unibrand){echo "compad with:$chunck_itemmodel";
}}}}}
WHY WONT THIS WORK!? Please.. Thank you for any Help.. be kind, im New!