Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Any way to get new variable value after outputting results?

    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?

    PHP Code:
    unset($variable); 
    ..or will that set it to nothing?

    Thanks for any help!

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    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.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,078
    Thanks
    11
    Thanked 98 Times in 96 Posts
    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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    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?

    PHP Code:
    <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!

  • #5
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Btw.. noticed you are from Perth

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •