Jump to content

Recommended Posts

alright, soI want to query a table and grab the last record in a desc order and assign it plus one.

 

My code so far for testing is:

 


<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

include "connect.php";

$result = mysql_query("SELECT * FROM tickets ORDER BY id DESC LIMIT 1");

echo "<table cellpadding='4' cellspacing='4'><tr>
<th>id</th></br>

</tr>";while($row = mysql_fetch_array($result))
  {
  echo "<tr><td>" . $row['id'] . "</td></tr>";
  }
echo "</table>";


?>

 

 

So I can display the returned value, but how can I assign the returned value to a php variable?

 

Link to comment
https://forums.phpfreaks.com/topic/218262-assign-a-php-value/
Share on other sites

That's what I thought, but I can't get the value to display, is there something missing from the code? I can display the value within the table, but when I call the value in a simple echo statement, the value is blank. the little things that drive you batty.

 


<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

include "connect.php";

$result = mysql_query("SELECT * FROM tickets ORDER BY id DESC LIMIT 1");

echo "<table cellpadding='4' cellspacing='4'><tr>
<th>id</th></br>


</tr>";while($row = mysql_fetch_array($result))
  {
echo "<tr><td>" . $row['id'] . "</td></tr>";
  }
echo "</table>";

ticketnum= $row['id'];

echo "hello" . ticketnum . "!";
?>


Link to comment
https://forums.phpfreaks.com/topic/218262-assign-a-php-value/#findComment-1132622
Share on other sites

Note: Since you are limiting the SELECT to one row, you don't really need to use the WHILE loop:

 


<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

include "connect.php";

$result = mysql_query("SELECT * FROM tickets ORDER BY id DESC LIMIT 1");

echo "<table cellpadding='4' cellspacing='4'><tr>
<th>id</th></br>


</tr>";
$row = mysql_fetch_array($result);
echo "<tr><td>" . $row['id'] . "</td></tr>";
echo "</table>";

$ticketnum= $row['id'];

echo "hello" . $ticketnum . "!";
?>

Link to comment
https://forums.phpfreaks.com/topic/218262-assign-a-php-value/#findComment-1132777
Share on other sites

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.