dwise159 Posted March 10, 2014 Share Posted March 10, 2014 <html> <head> <title>Albums</title> <link rel="stylesheet" href="css/Site.css"> </head> <body> <?php include "includes/header.php"; ?> <div id="main"> <h1>ALBUMS</h1> <!-- Buttons at top of page --> <span class="button"><a title="Add New Button" href="add_new_album.php">Add New Album</a></span> </br></br> <?php /* VIEW.PHP Displays all data from 'players' table */ // connect to the database include('includes/dbconnect.php'); // Set image folder path $images_path = "images"; $images_path .= "/"; // number of results to show per page $per_page = 6; // figure out the total pages in the database $result = mysql_query("SELECT * FROM albums ORDER BY album_id"); $total_results = mysql_num_rows($result); $total_pages = ceil($total_results / $per_page); // get results from database //$result = mysql_query("SELECT * FROM albums ORDER BY album_id") // or die(mysql_error()); // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1) if (isset($_GET['page']) && is_numeric($_GET['page'])) { $show_page = $_GET['page']; // make sure the $show_page value is valid if ($show_page > 0 && $show_page <= $total_pages) { $start = ($show_page -1) * $per_page; $end = $start + $per_page; } else { // error - show first set of results $start = 0; $end = $per_page; } } else { // if page isn't set, show first set of results $start = 0; $end = $per_page; } // display pagination echo "<p><a href='albums.php'>View All</a> | <b>View Page:</b> "; for ($i = 1; $i <= $total_pages; $i++) { echo "<a href='albums_paginated.php?page=$i'>$i</a> "; } echo "</p>"; // display data in table //echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>"; //Table headings echo "<table border='1' cellpadding='5'>"; echo "<tr><th>ID</th><th>Image</th><th>Artist</th><th>Title</th> <th>Label</th><th>Year</th><th>Matrix No</th><th>Speed</th> <th>Condition</th><th>Grading</th><th>Price</th><th>Catagory <th>Postage</th></th><th></th><th></th><th></th></tr>"; // loop through results of database query, displaying the pictures in the table //while($row = mysql_fetch_array( $result )) { for ($row = $start; $row < $end; $row++) { // make sure that PHP doesn't try to show results that don't exist if ($row == $total_results) { break; } $picture = $row['picture']; $thumb_picture = pathinfo($images_path.$picture, PATHINFO_FILENAME).'_thumb.'.pathinfo($images_path.$picture, PATHINFO_EXTENSION); // echo out the contents of each row into a table echo "<tr>"; echo '<td>' . mysql_result($result, $row, 'album_id') . '</td>'; echo '<td><a href="'. mysql_result($result, $images_path.$picture) .'"><img src="'. mysql_result($result, $images_path.$thumb_picture) .'"/></a> </td>'; echo '<td>' . mysql_result($result, $row, 'artist') . '</td>'; echo '<td>' . mysql_result($result, $row, 'title') . '</td>'; echo '<td>' . mysql_result($result, $row, 'record_label') . '</td>'; echo '<td>' . mysql_result($result, $row, 'year') . '</td>'; echo '<td>' . mysql_result($result, $row, 'matrix') . '</td>'; echo '<td>' . mysql_result($result, $row, 'speed') . '</td>'; echo '<td>' . mysql_result($result, $row, 'neworused') . '</td>'; echo '<td>' . mysql_result($result, $row, 'grading') . '</td>'; echo '<td>' . mysql_result($result, $row, 'price') . '</td>'; echo '<td>' . mysql_result($result, $row, 'catagory') . '</td>'; echo '<td>' . mysql_result($result, $row, 'postage') . '</td>'; echo '<td><a href="album_view.php?album_id=' . mysql_result($result, $row, 'album_id') . '">View</a></td>'; echo '<td><a href="album_edit.php?album_id=' . mysql_result($result, $row, 'album_id') . '">Edit</a></td>'; echo "<td><a href='album_delete.php?album_id=" . mysql_result($result, $row, 'album_id') . "' onclick=\"return confirm('Are you sure you want to delete?');\">Delete</a></td>"; echo "</tr>"; } echo "</table>"; ?> <?php include "includes/footer.php"; ?> </div> </body> </html> Hi have spent the last 2 days going cross eyed at the problem I am getting with the attached code. can anyone help, its something simple but I have looked too long and too hard now. Another pair of eyes would really be appreciated thanks Error Message: Warning: mysql_result() expects parameter 2 to be long, string given in C:\wamp\www\DAWrecords\albums_paginated.php on line 96 Quote Link to comment https://forums.phpfreaks.com/topic/286853-mysql_result-expects-parameter-2-to-be-long/ Share on other sites More sharing options...
ginerjm Posted March 10, 2014 Share Posted March 10, 2014 Your problem is that you didn't check for an error in your query. ALWAYS ALWAYS ALWAYS check the result of a function call before assuming that you have something to continue on with. Quote Link to comment https://forums.phpfreaks.com/topic/286853-mysql_result-expects-parameter-2-to-be-long/#findComment-1472013 Share on other sites More sharing options...
dwise159 Posted March 10, 2014 Author Share Posted March 10, 2014 Thanks well spotted I have corrected this and added the die function however this has not solved the original line 96 problem, thanks for looking thoughecho '<td><a href="'. mysql_result($result, $images_path.$picture) .'"><img src="'. mysql_result($result, $images_path.$thumb_picture) .'"/></a> </td>'; Quote Link to comment https://forums.phpfreaks.com/topic/286853-mysql_result-expects-parameter-2-to-be-long/#findComment-1472017 Share on other sites More sharing options...
ginerjm Posted March 10, 2014 Share Posted March 10, 2014 You only have one query running here and you are NOT checking the result of it. // figure out the total pages in the database $result = mysql_query("SELECT * FROM albums ORDER BY album_id"); //***** CHECK QUERY RESULTS !!!!!!! $total_results = mysql_num_rows($result); $total_pages = ceil($total_results / $per_page); You are also doing two things wrong with your data retrieval 1 - you are not retrieving a row 2 - you are using a horribly wasteful function to get the columns. Look up MySQL_fetch_assoc in the manual and stop getting your data field by field. MySQL_result is perfect if you are only seeking one piece of data, but if you want the entire row (as you do here), you should get the whole row at one time. Quote Link to comment https://forums.phpfreaks.com/topic/286853-mysql_result-expects-parameter-2-to-be-long/#findComment-1472022 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.