{help needed} - using msql and php to display records

Hi i would like to know why my code isn’t storing information into the stated variables after ive clicked the next record button

This is the defined variables’s :

[php]

<?php $sql=mysql_query("SELECT *FROM clients WHERE id > 0 ORDER BY id ASC LIMIT 1"); $row=mysql_fetch_array($sql); $id=$row['id']; $FirstName=$row['FirstName']; $Surname=$row['Surname']; $DOB=$row['DOB']; $Nationality=$row['Nationality']; ?>

[/php]

And when i press the “Next record” button, the data inside the variables should change to the “current” data but it doesn’t.

[php]

<?php if($_REQUEST['chngRecord'] == 'Next Record') { $sql=mysql_query("SELECT *FROM clients WHERE id > {$id} LIMIT 1"); $row=mysql_fetch_array($sql); $id=$row['id']; $FirstName=$row['FirstName']; $Surname=$row['Surname']; $DOB=$row['DOB']; $Nationality=$row['Nationality']; echo $id; } [/php]

Firstly:
Your SQL syntax has a slight error.

SELECT *FROM clients WHERE id > 0 ORDER BY id ASC LIMIT 1

Should be:

SELECT * FROM clients WHERE id > 0 ORDER BY id ASC LIMIT 1

Second: Can we see the code you use for the button?

[php]

[/php]

Here you go .

Does it really matter if its *from ? before I think I’ve tried it either way and didn’t make a difference. Cant really remember though. :’(

try this
[php]

$result = mysql_query(“SELECT *FROM clients WHERE id > 0 ORDER BY id ASC LIMIT 1”);
while($row = mysql_fetch_array($result))
{
$id=$row[‘id’];
$FirstName=$row[‘FirstName’];
$Surname=$row[‘Surname’];
$DOB=$row[‘DOB’];
$Nationality=$row[‘Nationality’];
}
[/php]

If I put a loop in there then it would change the variables to the last record which is not what i want. I want it to change to the next record by clicking a button

first you need to change the form to method post and $_REQUEST[‘chngRecord’] to $_POST[‘chngRecord’]
you need to make a new variable to show the next row
[php]
$nextrecord=$id+1;
//and change in the if statemnet
$sql=mysql_query(“SELECT * FROM clients WHERE id=’”.$nextrecord."’ ");
[/php]
I hope this will help you.

I checked if you can use the $_post or $_request non of them worked, I need a value from a form.

sorry I again need some coffee, I mean from text field.

i will check it asap. Thanks for helping :-*

Sponsor our Newsletter | Privacy Policy | Terms of Service