Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Problem with MySQL query. The function is only running for the first mysql result
    primarykey
    data
    text
    <p>I tried to search for something similar in the web but no results. What I am trying to do is simply taking the results from the DATABASE and then run some functions for EACH result. We have two kinds of functions. The first function is when the row "Type" is = F , the second one when the row "Type" is = T. The problem that I am having with this code is that it runs the functions ONLY for the first mySQL result. But I have more results in the same time, and the functions should run for EACH mySQL result and not only for the first one.</p> <p>I do not know if I need a foreach or whatever. I do not know anything about arrays and php loops.</p> <p>Thank you.</p> <pre><code>include_once("../dbconnection.php"); date_default_timezone_set('UTC'); $TimeZone ="UTC"; $todaydate = date('Y-m-d') ."\n"; $time_utc=mktime(date('G'),date('i'),date('s')); $NowisTime=date('G:i:s',$time_utc); $MembID =(int)$_COOKIE['Loggedin']; $DB = new DBConfig(); $DB -&gt; config(); $DB -&gt; conn(); $queryMAIN="SELECT * FROM TableTuit WHERE TimeZone ='".$TimeZone."' AND Date ='".$todaydate."' ORDER BY ID ASC"; $result=mysql_query($queryMAIN) or die("Errore select TableT: ".mysql_error()); $tot=mysql_num_rows($result); while($ris=mysql_fetch_array($result)){ $text=$ris['Tuitting']; $account=$ris['IDAccount']; $memberID=$ris['memberID']; $type=$ris['Type']; $id=$ris['ID']; $time=$ris['Time']; if($time &lt;= $NowisTime){ if($type=="F") //if the row type is = F, then do the things below { $queryF ="SELECT * FROM `TableF` WHERE `memberID`='$MembID' AND `ID`='$account'"; $result=mysql_query($queryF) or die("Errore select f: ".mysql_error()); $count = mysql_num_rows($result); if ($count &gt; 0) { $row = mysql_fetch_assoc($result); DO FUNCTION // Should call the function that requires the above selected values from $queryF. Should Run this function for every mysql result given by $queryMAIN where row "type" is = F } } } if($type=="T") //if the row type is = T, then do the things below { $queryT = $queryF ="SELECT * FROM `TableT` WHERE `memberID`='$MembID' AND `ID`='$account'"; $result=mysql_query($queryT) or die("Errore select $queryT: ".mysql_error()); $count = mysql_num_rows($result); if ($count == 0) $Isvalid = false; else { $Isvalid = true; $row = mysql_fetch_assoc($result); } if($Isvalid){ DO THIS FUNCTION // Should call the function that requires the above selected values from $queryT. Should Run this function for every mysql result given by $queryMAIN where row "type" is = T } } } }//END OF MYSQL WHILE OF $queryMAIN </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload