Jump to content

Recommended Posts

Hi guys, can u help me to see what im doing wrong here?

 

i keep getting this error

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

when i remove  LIMIT $start, $per_page" it works but im working on pagination,

 

thanks guys

 

 

<?php

session_start();

include ("../global.php");
//welcome messaage
$username=$_SESSION['username'];
echo "$username";

$query=mysql_query("SELECT id FROM users WHERE username='$username'");
while($row = mysql_fetch_array($query))
{
$id = $row['id'];
echo "$id";
}
//get pageinatio in each page
$per_page=5;


$start=$_GET['start'];
$record_count =mysql_num_rows(mysql_query("SELECT * FROM msg"));


$max_page=$record_count/$per_page;

$get= mysql_query("SELECT id, title,reference FROM msg LIMIT $start, $per_page");

while($row = mysql_fetch_assoc($get))
{

$title=$row['title'];
$reference=$row['msg'];


echo "$title";
}
?>

<table>

<td><?php echo $reference; ?></td></tr>
<td><?php echo $title; ?></td></tr>

        </table>

Link to comment
https://forums.phpfreaks.com/topic/222015-what-im-doing-wrong-help-plzzzz/
Share on other sites

$query=mysql_query("SELECT id FROM users WHERE username='$username'");
while($row = mysql_fetch_array($query))
{
$id = $row['id'];
echo "$id";
}

 

 

to

$query=mysql_query("SELECT id FROM users WHERE username='$username'");
while($row = mysql_fetch_assoc($query))
{
$id = $row['id'];
echo $id;
}

 

$start isn't defined.

 


if( intval($_GET['start']) < 1 ) {
    $start = 0;
} else {
    $start = (int) $_GET['start'];
}
[/code]

 

(Double check the var names, I had to type this on my phone.)

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.