0

Hello, I'm trying to run on 15 rows ONLY! each time.

First, this is my code-

PHP:

<div id ="items">
    <?php
    include './DateBaseLogOn.php';
    $sql = "SELECT * FROM items LIMIT 0, 15";
    $RESULT=$conn->query($sql);
    if(!$conn) {
      die("Connection Failed: ".mysqli_connect_error());
    }
    $row = $RESULT->fetch_assoc();
    while($row = mysqli_fetch_array($RESULT))
    {
    echo "<div id =\"itembox\">";
    echo "<div id=\"itempicture\"><img src=\"getImage.php?id=."$row['id']".\" width=\"230\" height=\"140\" /></div>";
    echo "<div id=\"iteminfo\">"."Info:".$row['info'].
    "</br>"."Current price:".$row['price'].
    "</br>"."Time until expired:".$row['exp'].
    "</br>"."Offer avilable until:".$row['timeleft'].
    "</br>"."Place:".$row['location'].
    "</div>";
    echo "<button class=\"sendprice\" onclick=\"location.href=$link\">Place bid</button>";
    echo "</div>";
    }

My questions are:

1. I'm getting an error :

( ! ) Parse error: syntax error, unexpected '$row' (T_VARIABLE), expecting ',' or ';' in C:\wamp\www\index.php on line 87

If i delete the <img src=\"getImage.php?id=."$row['id']".\" width=\"230\" height=\"140\" />

it works but i need to put the image there...

2. how can i tell the while loop to run only on 15 rows? and how can i make it run on the next 15 row with a click of a button (look at the echo row before the last echo row).

  • 1
    I find it weird that you test $conn after you used it... Usually, I would test if (!$conn) and then use it with $conn->query... Also, I don't understand why you fetch_assoc and then mysqli_fetch_array. This line : echo "
    "; Should be written like this : echo "
    ";
    – Julien B. Mar 10 '17 at 15:23
  • You already told that to your while loop, LIMIT 0, 15 - see? – Your Common Sense Mar 10 '17 at 15:24
  • NOTE: You are not supposed to put your code in the `wamp\www` folder. You have now overwritten the WAMPServer homepage! – RiggsFolly Mar 10 '17 at 15:24
  • @JulienB. so i should put the "if statement" before the $RESULT right?, – NicePersonsLiveMore Mar 10 '17 at 15:30
  • @Your Common Sense i know i wrote it but still it only run once and it starts on my second row idk why.. – NicePersonsLiveMore Mar 10 '17 at 15:30
  • @RiggsFolly thats what i want to do though.... where you think i should put it ? – NicePersonsLiveMore Mar 10 '17 at 15:31
  • @JulienB. because for some reason you have one extra fetch in your code – Your Common Sense Mar 10 '17 at 15:33
  • Create a Virtual Hosts for all your projects [See this post on the WAMPServer Forum](http://forum.wampserver.com/posting.php?2,moderation,138456) or this answer http://stackoverflow.com/questions/23665064/project-links-do-not-work-on-wamp-server/23990618#23990618 – RiggsFolly Mar 10 '17 at 15:33
  • @NicePersonsLiveMore you might start at the 2nd line because you fetch once before your while loop (not sure). As for the if statement, you are testing it after you first used it... So yes, your test should be logically be done before you use it. And FYI, be aware that using LIMIT without ORDER BY might give you unexpected results. – Julien B. Mar 10 '17 at 15:42

1 Answers1

0
echo "<div id=\"itempicture\"><img src=\"getImage.php?id=."$row['id']".\" width=\"230\" height=\"140\" /></div>";

You have the . after and before $row, inside the quotes. They need to be outside of the quotes.

EDIT:

So the solution is:

echo "<div id=\"itempicture\"><img src=\"getImage.php?id=".$row['id']."\" width=\"230\" height=\"140\" /></div>";
Loko
  • 6,539
  • 14
  • 50
  • 78