Jump to content

assign a php value


sanchez77

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

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.