Jump to content

Im lost :(


spearchilduser

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.