spearchilduser Posted November 25, 2011 Share Posted November 25, 2011 Hi i did post this on another forum which i think was the wrong place so ive posted it here aswell hope that's ok Hi i am trying to implement a simple recomendation system where the user will select an answer usign Check boxes and each box will have a value 1 -4 Those values are then passed onto the next page. I am only trying to do it based on the Price firstly to break it down bit by bit as i am not a expert im realitvely new to PHP. I am having a error with this line while {$row = mysql_fetch_array($results,MYSQL_NUM)} //get the information from the database and store in a array THE FULL CODE SO IT CAN BE SEEN IN CONTEXT WITH THE REST IS : <?php $dbh = mysql_connect("localhost", "root")//THIS CONNECTS TO THE SERVER WITH YOUR DETAILS or die ('I cannot connect to the database because: ' . mysql_error());//IF IT CANNOT CONNECT, THIS ERROR MESSAGE WILL SHOW $results = mysql_select_db ("Computers");//THIS SELECTS THE CORRECT DATABASE FROM YOUR SERVER @$price = $_POST['price']; ?> <?PHP $total_price = 0; $total_ram = 0; $number_of_items = 0; $total_items=$number_of_items + 1 while {$row = mysql_fetch_array($results,MYSQL_NUM)} //get the information from the database and store in a array { $total_price = $row["Computer_price"] + $total_price ; // this should then start with 0 and keep adding the row up $total_items = $number_of_items = $number_of_items + 1; // this should do the same but with the item number }; $av_price = $total_price/$total_items ; //gives an average of the price attribute print $av_price //Price $lowav_price = 0; //sets the low price to 0 $medav_price = 0.75 * $av_price; // sets the next level to 75 % of the avarage $highav_price = 1.25 * $av_price; // sets the next level to 125% of the average <HTML> <BODY> // for the follwing bit the user will select a check box which will have a value and these are the cases for each option. //each option is set ot be either 0 - 75% of the average or 75%- 125 % of the average or 125% and above based ont he average of the Data in the table switch ($price) { case '1' : $price_low = 0; $price_high = >= $lowav_price ; print " (I would like to pay less and get less specifications) < ".$price_low."-".$price_high.">"; break; case '2' : $price_low = >=$lowav_price; $price_high = >=$highav_price; print " (I would like to pay for what I get so what I get is equivalent to the price) < ".$price_low."-".$price_high.">"; break; case '3' : $price_low = >=$highav_price ;$price_high = >=$highav_price; print " (I would prefer to Pay as much as possible to get the best computer) < ".$price_low."-".$price_high.">"; break; case '4' : $price_low = 0; $price_high = >=$highav_price ; " (I have no preference) < ".$price_low."-".$price_high.">"; break; } print ' price option = '.$price; print "<br>"; //gives the different vaules for each selection button on the input form for price ?> <strong> SELECTED CAMCORDERS </strong> <br> <table width="75%" border="1"> <tr> <td>Model</td> <td>Price</td> <td>Stabilization</td> <td>Optical zoom</td> <td>Image</td> </tr> <?PHP while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { if (($row["price"] >= $price_low) && ($row["price"] <= $price_high)) //price // if ($row["stabilization"] == $stabilizer_present) //stabilizer // if (($row["optical_zoom"] >= $zoom_low ) // && ($row["optical_zoom"]<= $zoom_high ) // && ($row_number < 5) ) //price //{ $row_number++; ?> <tr> <td align="center"><?php print $row["price"]; ?> </td> </tr> <?php //mysql_data_seek($result, 0); }//if }//while ?> </table> </body> </html> i AHVE TRIED TO ANNOTATE it so that you can see what i am trying to do wether i am or not is another question thanx for any replies Quote Link to comment https://forums.phpfreaks.com/topic/251781-simple-recomendation-system/ Share on other sites More sharing options...
Nodral Posted November 25, 2011 Share Posted November 25, 2011 Your syntax is out. This line should be somehting like while ($row = mysql_fetch_array($results){ //do somehting with each returned result as $row['xx'] } Quote Link to comment https://forums.phpfreaks.com/topic/251781-simple-recomendation-system/#findComment-1291152 Share on other sites More sharing options...
spearchilduser Posted November 25, 2011 Author Share Posted November 25, 2011 Hi thanx for the response so you say the syntax is out a little this is ofc the syntax im usign at the moment : while {$row = mysql_fetch_array($results,MYSQL_NUM)} { $total_price = $row["Computer_price"] + $total_price ; $total_items = $number_of_items = $number_of_items + 1; }; I dont undertsand how i can swap the syntax around as im increasing the value of $total_ price using the $row data or am i looking at it the wrong way aroudn im sorry as i say i am relatively new to this thanx again Quote Link to comment https://forums.phpfreaks.com/topic/251781-simple-recomendation-system/#findComment-1291162 Share on other sites More sharing options...
ignace Posted November 25, 2011 Share Posted November 25, 2011 He's saying that you should replace this line of code: while {$row = mysql_fetch_array($results,MYSQL_NUM)} With while ($row = mysql_fetch_array($results,MYSQL_NUM)) It's advised to consult the manual if you are new. Quote Link to comment https://forums.phpfreaks.com/topic/251781-simple-recomendation-system/#findComment-1291167 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.