PHP - my code always returns row 1

KevinUK

Can't get enough of FH
Joined
Dec 22, 2003
Messages
649
I am using dreamweaver where in the SQL view I press the test button and it returns the correct value, the SQL is a simple id = url id typed in.

The problem is on localhost and on my server the code always loads the data from row 1 :eek7:

The url is correct, content/file.php?id=2 yet when the page loads, the data is that of id 1 and not 2.

The code should work, I have similar code all over the site which works and like I said, its working in dream weaver.

Any ideas? It's not a one off, I coded something else which has the same problem. PHP is on the server, im using PHP forums etc... :(

Thanks :D
 

KevinUK

Can't get enough of FH
Joined
Dec 22, 2003
Messages
649
This lists urls on one page:

Code:
<?php
$colname_fileinfo = "1";
if (isset($HTTP_GET_VARS['Id'])) {
  $colname_fileinfo = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['Id'] : addslashes($HTTP_GET_VARS['Id']);
}
mysql_select_db($database_test, $test);
$query_fileinfo = sprintf("SELECT * FROM file WHERE Id = %s", $colname_fileinfo);
$fileinfo = mysql_query($query_fileinfo, $test) or die(mysql_error());
$row_fileinfo = mysql_fetch_assoc($fileinfo);
$totalRows_fileinfo = mysql_num_rows($fileinfo);
?>

//html and head tags etc here

<?php do { ?>
<a href="file.php?id=<?php echo $row_top10['Id']; ?>"><?php echo row_top10 'title']; ?></a>

<?php } while ($row_top10 = mysql_fetch_assoc($top10)); ?>

Click a url and on this page it should load the data related to the url clicked (currently always returns row 1 even if the url is /content/file.php?id=2):

Code:
<?php
$colname_fileinfo = "1";
if (isset($HTTP_GET_VARS['Id'])) {
  $colname_fileinfo = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['Id'] : addslashes($HTTP_GET_VARS['Id']);
}
mysql_select_db($database_test, $test);
$query_fileinfo = sprintf("SELECT * FROM file WHERE Id = %s", $colname_fileinfo);
$fileinfo = mysql_query($query_fileinfo, $test) or die(mysql_error());
$row_fileinfo = mysql_fetch_assoc($fileinfo);
$totalRows_fileinfo = mysql_num_rows($fileinfo);
?>

//html and head tags etc here

<? echo $row_fileinfo['title']; ?><br>
<? echo $row_fileinfo['filename']; ?><br>
<? echo $row_fileinfo['author']; ?>

The code is probably messy but I use dreamweaver to 'help' :eek:
 

wyrd_fish

Fledgling Freddie
Joined
Dec 27, 2003
Messages
537
it is tres messy...

it's prolly a single = instead of 2

on sets teh variable teh other is for checking

eg
$arse = "bum";
arse now = bum

if($arse == "bum"){...
checks if arse is bum


most of that is really dodgy code...

try this
Code:
$query = "select * from [b]table[/b] where id = $GET[id] limit 1";
$result = mysql_query($query);
$data = mysql_fetch_array($result);

$data[1] - the first colum
$data[2] - the second colum
$data[3] - the third colum
...or...
$data[title]
$data[filename]
$data[author]
 

wyrd_fish

Fledgling Freddie
Joined
Dec 27, 2003
Messages
537
bah... you can only edit in the 1st 10 mins of posting...

i missed some:(

Code:
if(isset($GET[id])){
    $id = $GET[id];
}else{
    $id = "1";
}

$query = "select * from table where id = $id limit 1";
$result = mysql_query($query);
$data = mysql_fetch_array($result);

that should work
 

KevinUK

Can't get enough of FH
Joined
Dec 22, 2003
Messages
649
AH NO WAY!!

It's always the simplest of things :(

In my table where I created the table, the id was spelt Id. It has to be lowercase. I always do lowercase, just not that time.

Me goes to hang myself! :twak:

Note to others: do lowercase :D
 

Users who are viewing this thread

Top Bottom