Jump to content

What im doing wrong? Help plzzzz


princeofpersia

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.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.