...

View Full Version : Any way to get new variable value after outputting results?



cyphix
05-10-2004, 06:37 PM
Ok... I have a variable set to a certain number which may or may not update during a while loop.

What I am wanting to do is print the value of this variable after it has got it's final result... but, I want to print this before the while loop ends.

Like... if I refer to it & tell PHP to print the value of it won't it print the current value of it at that time rather than print the final value of it? Depending on how the results go through the if statement in the while loop the variable setting may not get processed again to update to a newer value.

Can you just use something like?



unset($variable);


..or will that set it to nothing?

Thanks for any help!

cyphix
05-10-2004, 06:40 PM
Hmm.. thinking about it no matter what you set the variable to it's not going to matter.. the variable is at it's correct value but you are just trying to get an earlier print of it to show it's final value.

firepages
05-10-2004, 06:53 PM
err you may need to post some example code ? cos it sounds to me like you want the PHP timePhaseContinumDistortion module (not available until >=PHP6) , unless I misunderstand you which could be the case :D

cyphix
05-10-2004, 07:39 PM
LOL ok, here is the code...

I am wanting to put :$var search results found" at the top of the table (which would go inside the first "if" statement in the while loop.

Just for the record... for some reason my first "if" statement doesn't seem to be working.. when I do a search it prints out the whole database no matter if it finds a result or not. Am I comparing them wrong somehow?



<html>
<head>
<title>People's Info</title>
<style>
<!--
td { font-family: Arial; font-size: 13px}
a:link { color :blue; numeric-decoration: none; text-decoration: underline;}
a:visited { color :blue; numeric-decoration: none; text-decoration: underline;}

.ptext { font-family: Arial; font-size: 13px; font-weight: bold}

-->
</style>
</head>

<body>


<?php

require("db.php");

mysql_connect("sql2.xxxxxxxx.com", "$user", "$password") or die("Couldn't connect to server.");

@mysql_select_db("$database") or die("Couldn't connect to database.");

$query="SELECT*FROM contacts";

$results=mysql_query($query);

$num=mysql_numrows($results);

mysql_close();

$i = 0;
$search = 0;

while ($i < $num) {

$first = mysql_result($results, $i, "first");
$last = mysql_result($results, $i, "last");
$phone = mysql_result($results, $i, "phone");
$mobile = mysql_result($results, $i, "mobile");
$fax = mysql_result($results, $i, "fax");
$email = mysql_result($results, $i, "email");
$web = mysql_result($results, $i, "web");

if (strtolower($searchperson) == strtolower('$first') or strtolower('$last') or strtolower('$first $last')) {

if ($search == 0) {

echo "<table align=center border=1 cellpadding=1 cellspacing=1 width=70%>\n";

echo "<tr>\n";
echo "<td align=center>\n";
echo "<b>First Name</b>\n";
echo "</td>\n";
echo "<td align=center>\n";
echo "<b>Last Name</b>\n";
echo "</td>\n";
echo "<td align=center>\n";
echo "<b>Phone</b>\n";
echo "</td>\n";
echo "<td align=center>\n";
echo "<b>Mobile</b>\n";
echo "</td>\n";
echo "<td align=center>\n";
echo "<b>Fax</b>\n";
echo "</td>\n";
echo "<td align=center>\n";
echo "<b>Email</b>\n";
echo "</td>\n";
echo "<td align=center>\n";
echo "<b>Web</b>\n";
echo "</td>\n";
echo "</tr>\n";

echo "<tr>\n";
echo "<td>\n";
echo ($first);
echo "</td>\n";
echo "<td>\n";
echo ($last);
echo "</td>\n";
echo "<td>\n";
echo ($last);
echo "</td>\n";
echo "<td>\n";
echo ($mobile);
echo "</td>\n";
echo "<td>\n";
echo ($fax);
echo "</td>\n";
echo "<td>\n";
echo ($email);
echo "</td>\n";
echo "<td>\n";
echo ($web);
echo "</td>\n";
echo "</tr>\n";

} else {

echo "<tr>\n";
echo "<td>\n";
echo ($first);
echo "</td>\n";
echo "<td>\n";
echo ($last);
echo "</td>\n";
echo "<td>\n";
echo ($last);
echo "</td>\n";
echo "<td>\n";
echo ($mobile);
echo "</td>\n";
echo "<td>\n";
echo ($fax);
echo "</td>\n";
echo "<td>\n";
echo ($email);
echo "</td>\n";
echo "<td>\n";
echo ($web);
echo "</td>\n";
echo "</tr>\n";

}

$search++;

}

$i++;

if ($i == $num and $search != 0) {

echo "</table>";

}

}

if ($search == 0) {

echo "<b><font class=ptext>Idiot, there was no matches found in the database; try searching for someone else.</font></b>";

}

?>

</body>
</html>


Thanks!

cyphix
05-10-2004, 07:41 PM
Btw.. noticed you are from Perth :D

I'm from Perth too hehe... we are both up late! :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum