Jump to content

[SOLVED] How can I create a link that will change 'WHERE id = 1' by 1?


Recommended Posts

Hi!

I've got a page which displays various words and their translations based on their id numbers in a table.

 

<?php 
if ($_GET['english']=='on'){
$result = mysql_query( "SELECT English FROM $table WHERE id = 24");
while ( $pr_row = mysql_fetch_row( $result ) )
{
print "";
foreach ( $pr_row as $data )
print "\t $data";
print "\n";
}
print "\n";
mysql_close ( $link );
} 
?>

 

I'm trying to find a way to make a link that will +1 to the 'WHERE id' number so that it displays those numbers?

 

I'm really, really new to this stuff (been learning php since, oh, yesterday lunchtime) so I'd really appreciate any explainations you could give me!

Thanks!  ;D

I'm new to but this is an example of my blog edit page:

 

if ($num > 0) { // If it ran OK, display the records.

 

echo "<p>There are currntly $num Blog entries.</p>\n";

 

// Table header.

echo '<table align="center" cellspacing="0" cellpadding="5">

<tr>

<td align="left"><b>Date</b></td>

<td align="left"><b>Heading</b></td>

<td align="view"><b>View</b></td>

<td align="left"><b>Edit</b></td>

<td align="left"><b>Delete</b></td>

</tr>

';

 

// Fetch and print all the records.

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

echo '<tr>

<td align="left"><a href="blog_view.php?id=' . $row['blog_id'] . '">' . $row['date2'] . '</a></td>

<td align="left">' . $row['heading'] . '</td>

<td align="left"><a href="blog_view.php?id=' . $row['blog_id'] . '">View</a></td>

<td align="left"><a href="blog_edit4b.php?id=' . $row['blog_id'] . '">Edit</a></td>

<td align="left"><a href="delete_blog.php?id=' . $row['blog_id'] . '">Delete</a></td>

</tr>

';

}

 

 

Hope this helps.

I'm not sure if this is what you meant, but from what I've got, this could be what you are looking for:

 

<?php
$id = (int) $_GET['id'];
if($id == 0)
  $id = 24; //or any other default value that you want to set
  
if($_GET['english']=='on'){
  $result = mysql_query("SELECT English FROM $table WHERE id = $id LIMIT 1");
  /*while($pr_row = mysql_fetch_row($result)){
    // print ""; // why print an empty string? no use for this!
    foreach ( $pr_row as $data )
      print "\t $data"; 
      --->You don't need the foreach, because there is only one key in the array.
          
    print "\n";
  }*/ // you don't need the while either, because there can only be one row returned at most
  if($data = mysql_fetch_row($result)){
    $next_id = $id + 1;
    print($data[0].'<br /><a href="file.php?id='.$next_id.'">Next</a>'); //you might also want to escape the data with htmlentities()
  }
  else{
    //no row has been found!
  } 
} 
?>

Thanks phant0m, that works - but it raises another problem which I've been trying to work around fot the last half hour:

 

if I click 'next', and then hit "english" to make english=on it removes the id number.

 

I've tried changing it to be <a href="?id='$id'?english=on">English</a> but it won't work. I've tried google searches and searching the firums but haven't been able to find a solution.

Could you help?

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.