spearchilduser Posted November 28, 2011 Share Posted November 28, 2011 while($row = mysql_fetch_array($results, MYSQL_NUM)) { $total_price = $row["Computer_price"] + $total_price ; $total_items = $number_of_items = $number_of_items + 1; } This is the code and its telling em there is a parse error with line 16 which is the "while" line of code any suggestions at all? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/ Share on other sites More sharing options...
trq Posted November 28, 2011 Share Posted November 28, 2011 What is the exact error? Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1291800 Share on other sites More sharing options...
spearchilduser Posted November 28, 2011 Author Share Posted November 28, 2011 it does not say the error that it comign up is just "Parse error: parse error in C:\wamp\www\dancomp\show_computers.php on line 16" And i cannot see a problem on it thank you Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1291804 Share on other sites More sharing options...
trq Posted November 28, 2011 Share Posted November 28, 2011 It is likely that the error is actually occurring on a previous line. You'll need to post more code. Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1291806 Share on other sites More sharing options...
spearchilduser Posted November 28, 2011 Author Share Posted November 28, 2011 so the point of the system is a simple recomendation system where it will pull the data from the database store it in a array and then calculate the average and then depending on which option the user selcts on the previosu page it will show computers with a % of the average price in a table. <?php $dbh = mysql_connect("localhost", "root", "dancomp") or die ('I cannot connect to the database because: ' . mysql_error()); $results = mysql_select_db ("Computers"); @$price = $_POST['price']; $total_price = 0; $total_ram = 0; $number_of_items = 0; $total_items=$number_of_items + 1 while($row = mysql_fetch_array($results, MYSQL_NUM)) { $total_price = $row["Computer_price"] + $total_price ; $total_items = $number_of_items = $number_of_items + 1; } $av_price = $total_price/$total_items ; 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>"; ?> <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> Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1291810 Share on other sites More sharing options...
trq Posted November 28, 2011 Share Posted November 28, 2011 You are missing a ; on $total_items=$number_of_items + 1 Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1291812 Share on other sites More sharing options...
spearchilduser Posted November 28, 2011 Author Share Posted November 28, 2011 Thank you can you see any probelms around the switch () area as it says the same thing for that and i cannot find a parse error after looking thanx for your replies fell a little stupid now Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1291815 Share on other sites More sharing options...
trq Posted November 28, 2011 Share Posted November 28, 2011 What is the go with these? = >= Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1291823 Share on other sites More sharing options...
spearchilduser Posted November 28, 2011 Author Share Posted November 28, 2011 they are so that the price low/price high are equal or less than / equal to or more than lowav_price or highav_price depending on which function was called next to them thsi is beacuse depending on the answer the user selects the searhc on the databse will be 0 - 75% of the average 75-125% of the average or 125%+ pf the average in this case it will be of the average price in the database Thanks Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1291826 Share on other sites More sharing options...
spearchilduser Posted November 29, 2011 Author Share Posted November 29, 2011 hey im re posting this as i got no answers and im stucka nd confused when ive looked up this it says that ive used a function twice or somethign but the error im getting is Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\dancomp\show_computers.php on line 17 which is the while () line it also says it later on when i try to do another while statement please help heres my code if it helps. results = mysql_select_db ("computers"); $total_price = 0; $total_ram = 0; $number_of_items = 0; $total_items=$number_of_items + 1; while($row = mysql_fetch_array($results, MYSQL_BOTH)) { $total_priceav = $row["Computer_Price"] + $total_price ; $total_items = $number_of_items = $number_of_items + 1; } $av_price = $total_price/$total_items; print $av_price; Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1292115 Share on other sites More sharing options...
MasterACE14 Posted November 29, 2011 Share Posted November 29, 2011 $results = mysql_select_db ("computers"); is not a resource. You need a mysql_query() which will return either a resource, true or false. Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1292116 Share on other sites More sharing options...
spearchilduser Posted November 29, 2011 Author Share Posted November 29, 2011 aww right ok then thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1292126 Share on other sites More sharing options...
spearchilduser Posted November 29, 2011 Author Share Posted November 29, 2011 ok then thank you thats all been done my next probelm now thats resolves is its saying " "Notice: Undefined index: Computer_Price in C:\wamp\www\dancomp\show_computers.php on line 23" Which is this line while($row = mysql_fetch_array($result, MYSQL_NUM)) { ---->>> $total_price = $row["Computer_Price"] + $total_price ; <---------- $total_items = $number_of_items = $number_of_items + 1; } How ever it is a attribute in my table spelt correctly this si used to connect it all $query = "SELECT * FROM computer_details"; // Retrieve all the data from the "computers" table $result = mysql_query($query) or die(mysql_error()); im not sure if ive gotten the way of doign it wrong do i have to out the whoel database into a query then make another to pull just the table im stucka nd relatively new thanx Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1292135 Share on other sites More sharing options...
spearchilduser Posted November 29, 2011 Author Share Posted November 29, 2011 Any help would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1292139 Share on other sites More sharing options...
MasterACE14 Posted November 29, 2011 Share Posted November 29, 2011 is 'Computer_Price' the correct name of the field? EDIT: Noticed you changed the second argument of mysql_fetch_array to MYSQL_NUM. Change your while loop to this and it should work fine: while($row = mysql_fetch_array($result)) MYSQL_NUM means the fields are numbered with an index. Which you don't want if you're calling a field by it's name rather than an id. Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1292157 Share on other sites More sharing options...
spearchilduser Posted November 29, 2011 Author Share Posted November 29, 2011 Hi thanx for the reply ive gotta go to work now so ill try it later and hope nothing else is wrong Thanx again Quote Link to comment https://forums.phpfreaks.com/topic/251955-im-lost/#findComment-1292164 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.