Jump to content

phil5529

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

phil5529's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you very much! I am reading and reading, a few parts dont make sense to me (as in i dont understand them) but I am looking them up as we speak... I have sorted out other errors however I am still getting an error but I cant see for the life of me what is wrong with it, I recieve the error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\xampp\htdocs\blurb2\products.php on line 55 Line 55 is: Line 53: //Prepare output Line 54: $recordsHTML = ''; Line 55: while ($row = mysql_fetch_assoc($query)) Line 56: { Line 57: $urlParams = "bookname={$row['bookname']}&bookauthor={$row['bookauthor']}&bookpub={$row['bookpub']}&bookisbn={$row['bookisbn']}"; Line 58: $recordsHTML .= "<tr>\n"; Line 59: $recordsHTML .= " <td><a href='addtolist.php?{$urlParams}'>Add to basket</a></td>\n"; Line 60: $recordsHTML .= " <td>$bookname</td>\n"; Line 61: $recordsHTML .= " <td>$bookauthor</td>\n"; Line 62: $recordsHTML .= " <td>$bookpub</td>\n"; Line 63: $recordsHTML .= " <td>$bookisbn</td>\n"; Line 64: $recordsHTML .= "</tr>\n"; Line 65: } I really cant explain how grateful I am for your wisdom... thank you! [=
  2. I am very new new php (wrote my first PHP script 5 Days ago) and am trying to give myself a crash course but I have hit a pit-stop which is killing me a little! I hope that title makes sense.... Basically I created PHP script to take data from a database and display in, I then wrote some code to use a drop down menu to order that data. That all worked ok until I tried to utilise some pagination. I can make the pagination work, and I can make the ordering work, but not at the same time! At the moment the code that I have will allow me to order the list and almost paginate it. There are 40 results and I want to display 10 at a time. When not using the ordering code I can paginate it perfectly but when I try to intergrate the two bits of code it will only display the first 10 results and not give me an option to go to the next page to see the rest! The code: if (!isset($_GET['start'])) { $_GET['start'] = 0; } $per_page = 10; $start = $_GET['start']; if (!$start) $start = 0; $sort = @$_POST['order']; if (!empty($sort)) { $get = mysql_query("SELECT bookname, bookauthor, bookpub, bookisbn FROM booktable ORDER BY ".mysql_real_escape_string($_POST['order'])." ASC LIMIT $start, $per_page"); } else { $get = mysql_query("SELECT bookname, bookauthor, bookpub, bookisbn FROM booktable ORDER BY bookname ASC LIMIT $start, $per_page"); } $record_count = mysql_num_rows($get); ?> <?php if (isset($_GET['showerror'])) $errorcode = $_GET['showerror']; else $errorcode = 0; ?> wont include all the html rubbish and the ordering menu! <div id="mid"> <?php echo "<table>"; echo "<tr>"; echo "<th>"; echo "</th>"; echo "<th>"; echo "Book Title"; echo "</th>"; echo "<th>"; echo "Book Author"; echo "</th>"; echo "<th>"; echo "Book Publisher"; echo "</th>"; echo "<th>"; echo "Book ISBN"; echo "</th>"; echo "<th>"; echo "</th>"; echo "</tr>"; while ($row = mysql_fetch_assoc($get)) { // get data $bookname = $row['bookname']; $bookauthor = $row['bookauthor']; $bookpub = $row['bookpub']; $bookisbn = $row['bookisbn']; echo "<tr>"; echo "<td>"; echo "<a href='addtolist.php?bookname=".$bookname."&bookauthor=".$bookauthor."&bookpub=".$bookpub."&bookisbn=".$bookisbn."'>Add to basket</a>"; echo "</td>"; echo "<td>"; echo $bookname; echo "</td>"; echo "<td>"; echo $bookauthor; echo "</td>"; echo "<td>"; echo $bookpub; echo "</td>"; echo "<td>"; echo $bookisbn; echo "</td>"; echo "</tr>"; } echo "</table>"; $prev = $start - $per_page; $next = $start + $per_page; if (!($start<=0)) echo "<a href='products.php?start=$prev'>Prev</a> "; //set variable for first page number $i=1; //show page numbers for ($x = 0; $x < $record_count; $x = $x + $per_page) { if ($start != $x) echo "<a class='pagin' href='products.php?start=$x'> $i </a>"; else echo "<a class='pagin' href='products.php?start=$x'><b> $i </b></a>"; $i++; } //show next button if (!($start >= $record_count - $per_page)) echo "<a class='pagin' href='products.php?start=$next'> Next </a>"; ?> Thank you so much for reading!
×
×
  • 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.