?
Solved

trying to check status then load data

Posted on 2005-03-18
28
Medium Priority
?
184 Views
Last Modified: 2008-03-06
I am trying to do if status =1 then will print out letter or else print out numbe of that record but doesn't seme to be doing anything using the code below

<link href="style1.css" type="text/css" rel="stylesheet">
<?php
require 'db_connect2.php';

$result = mysql_query("SELECT * FROM "sqlb"");
$output= "<table border='1' align='center'>";
 
  for($i=0;$i<9;$i++){
   
     $row = mysql_fetch_row($result);
      $output.="<tr>";
   
    //get table
    for($k=0;$k<9;$k++){
    if ($row[$k]==0)
    {
    $output.= "<td Class=f1>B".$row[$k]."</td>"; //blank block
    }
    else
    {
 
    $filter = mysql_query ("SELECT * FROM sqla WHERE STATUS = '1'");
          if ($row[$k] == $filter["NUM"]){
                $tabledata = $filter["LETT"];
                }
                else
                {
                $tabledata = $row[$k];
                }
    }
      $output.= "<td>".$tabledata."</td>";
   
     $output.= "</tr>";
     $output.="</table>";  
     }
 //display table
     echo       "$output";

?>
0
Comment
Question by:htse011498
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 15
  • 12
28 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 13573143
A mysql_fetch_array() is missing

Try

<link href="style1.css" type="text/css" rel="stylesheet">
<?php
require 'db_connect2.php';

$result = mysql_query("SELECT * FROM "sqlb"");
$output= "<table border='1' align='center'>";
 
  for($i=0;$i<9;$i++){
   
     $row = mysql_fetch_row($result);
      $output.="<tr>";
   
    //get table
    for($k=0;$k<9;$k++){
    if ($row[$k]==0)
    {
        $output.= "<td Class=f1>B".$row[$k]."</td>"; //blank block
    }
    else
    {
 
            $res = mysql_query ("SELECT * FROM sqla WHERE STATUS = '1'");
            $filter = mysql_fetch_array($res);
         if ($row[$k] == $filter["NUM"]){
              $tabledata = $filter["LETT"];
         }
         else
         {
              $tabledata = $row[$k];
         }
    }
      $output.= "<td>".$tabledata."</td>";
   
     $output.= "</tr>";
     $output.="</table>";  
     }
 //display table
     echo      "$output";

?>
0
 

Author Comment

by:htse011498
ID: 13573206
This is what I changed but doens't seem to be workign?
<?php
require 'db_connect2.php';

$result = mysql_query("SELECT * FROM sqlb");
$compare = mysql_query("SElECT * FROM sqla");
$output= "<table border='1' align='center'>";
 
  for($i=0;$i<9;$i++){
   
     $row = mysql_fetch_row($result);
      $output.="<tr>";
    //replace function
    for ($j=0;$j<9;$j++) if ($STATUS=='1')  
   $row[$j]=$LETT;
   
    //get table
    for($k=0;$k<9;$k++){
    if ($row[$k]==0){
    $output.= "<td Class=f1>B".$row[$k]."</td>";}
    else
          $check = mysql_query("SELECT * FROM sqla WHERE NUM = '".$row[$k]."' and STATUS = '1');
          if (empty($check)){
                  $output.= "<td>".$row[$k]."</td>";}
          else {
                $output.= "<td>".$check[LETT]."</td>";}
     $output.= "</tr>";}
     $output.="</table>";  
     
 //display table
     echo       "$output"

?>
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13573252
Try this:

<?php
require 'db_connect2.php';

$result = mysql_query("SELECT * FROM sqlb");
$compare = mysql_query("SElECT * FROM sqla");
$output= "<table border='1' align='center'>";
 
  for($i=0;$i<9;$i++){
   
     $row = mysql_fetch_row($result);
      $output.="<tr>";
    //replace function
    for ($j=0;$j<9;$j++) if ($STATUS=='1')  
   $row[$j]=$LETT;
   
    //get table
    for($k=0;$k<9;$k++){
    if ($row[$k]==0){
    $output.= "<td Class=f1>B".$row[$k]."</td>";}
    else
         $res = mysql_query("SELECT * FROM sqla WHERE NUM = '".$row[$k]."' and STATUS = '1'");
         $check = mysql_fetch_array($res);
         if (!$check["LETT"]){
                $output.= "<td>".$row[$k]."</td>";}
         else {
              $output.= "<td>".$check["LETT"]."</td>";}
     $output.= "</tr>";}
     $output.="</table>";  
     
 //display table
     echo      "$output"

?>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:elhkwt
ID: 13573297
It's not working. I've tried this and it can print the table, but can't change the content to LETT when $STATUS=1

<?php
require 'db_connect2.php';

$result = mysql_query("SELECT * FROM sqlb");
$output= "<table border='1' align='center'>";
 
  for($i=0;$i<9;$i++){
   $row = mysql_fetch_row($result);
   
      $output.="<tr>";
     
    //replace function
    $result2 = mysql_query("SELECT * FROM sqla WHERE $STATUS=='1'");
 while( $row2 = mysql_fetch_array($result2)){
    for ($j=0;$j<9;$j++)
   $row[$j]=$LETT;}
   
    //get table
    for($k=0;$k<9;$k++){
    if ($row[$k]==0){
    $output.= "<td Class=f1>B".$row[$k]."</td>";}
    else
      $output.= "<td>".$row[$k]."</td>";}
   
     $output.= "</tr>";}
     $output.="</table>";  
     
 //display table
     echo       "$output"

?>
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13573341
So the content should be "LETT" when status=1

Try this:


<?php
require 'db_connect2.php';

$result = mysql_query("SELECT * FROM sqlb");
$compare = mysql_query("SElECT * FROM sqla");
$output= "<table border='1' align='center'>";
 
  for($i=0;$i<9;$i++){
   
     $row = mysql_fetch_row($result);
      $output.="<tr>";
    //replace function
    for ($j=0;$j<9;$j++) if ($STATUS=='1')  
   $row[$j]=$LETT;
   
    //get table
    for($k=0;$k<9;$k++){
    if ($row[$k]==0){
    $output.= "<td Class=f1>B".$row[$k]."</td>";}
    else
         $res = mysql_query("SELECT * FROM sqla WHERE NUM = '".$row[$k]."' and STATUS = '1'");
         $check = mysql_fetch_array($res);
         if (!$check["LETT"]){
                $output.= "<td>".$row[$k]."</td>";}
         else {
              $output.= "<td>LETT</td>";}
     $output.= "</tr>";}
     $output.="</table>";  
     
 //display table
     echo      "$output"

?>
0
 

Expert Comment

by:elhkwt
ID: 13573381
just have a go with it, the problem is still there. No table display..
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13573409
Could you explain a little bit more what you are trying to do?

why the

for($i=0;$i<9;$i++){

and

for ($j=0;$j<9;$j++)
0
 

Expert Comment

by:elhkwt
ID: 13573438
for($i=0;$i<9;$i++){  is to go through the rows in the table
for ($j=0;$j<9;$j++) is to go through the columns in the row[i]

the table is display like this:
B0 26 4 17 7 1 10 B0 20
4 B0 2 B0 24 B0 6 B0 7
2 17 16 14 3 6 2 B0 6
9 B0 19 B0 24 B0 13 B0 8
17 22 24 1 8 B0 6 2 11
6 B0 8 B0 B0 B0 19 B0 20
3 17 8 10 12 25 B0 B0 4
B0 B0 17 B0 B0 B0 B0 B0 14
23 4 2 1 8 24 12 2 B0


0
 
LVL 32

Expert Comment

by:Batalf
ID: 13573500
Try the code below. If that isn't working please explain the design of table sqla and sqlb, i.e. the columns of these tables.:

$result = mysql_query("SELECT * FROM sqlb");
$output= "<table border='1' align='center'>";
while($row = mysql_fetch_array($result)){
      $output.="<tr>";
      $result2 = mysql_query("SELECT * FROM sqla WHERE NUM = '".$row[0]."'");
      while($row2 = mysql_fetch_row($result2)){
            if($row2["STATUS"]){
                  $output.= "<td>".$row2[0]."</td>";
            }else{
                  $output.= "<td>LETT</td>";      
            }      
      }
      $output.= "</tr>";
}
$output.="</table>";
0
 

Expert Comment

by:elhkwt
ID: 13573556
still not getting there.

sqla got 3 columns:
NUM  int(27)                
LETT  varchar(27)                  
STATUS  tinyint(1)   //set to "0" for all

sqlb got 9 columns:
   C1  int(9)              
   C2  int(9)                  
   C3  int(9)                
   C4  int(9)                
   C5  int(9)                  
   C6  int(9)                
   C7  int(9)                  
   C8  int(9)                
   C9  int(9)    

0
 
LVL 32

Expert Comment

by:Batalf
ID: 13573633
OK, then I hope this code will help you.


$result = mysql_query("SELECT * FROM sqlb");
$output= "<table border='1' align='center'>";
if($row = mysql_fetch_row($result)){
      $output.="<tr>";
      for($no=0;$no<9;$no++){
            $result2 = mysql_query("SELECT * FROM sqla WHERE NUM = '".$row[$no]."'");
            if($row2 = mysql_fetch_array($result2)){
                  if($row2["STATUS"]){
                        $output.= "<td>".$row2["LETT"]."</td>";
                  }else{
                        $output.= "<td>LETT</td>";      
                  }      
            }
      }
      $output.= "</tr>";
}
$output.="</table>";
0
 

Expert Comment

by:elhkwt
ID: 13573672
bad news. the table is not loading up.
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13573695
And you remembed to put in

echo $output;

at the bottom?

How does the table look now?
0
 

Expert Comment

by:elhkwt
ID: 13573744
still got no table

<?php
require 'db_connect2.php';

$result = mysql_query("SELECT * FROM sqlb");
$output= "<table border='1' align='center'>";
if($row = mysql_fetch_row($result)){
     $output.="<tr>";
     for($no=0;$no<9;$no++){
          $result2 = mysql_query("SELECT * FROM sqla WHERE NUM = '".$row[$no]."'");
          if($row2 = mysql_fetch_array($result2)){
               if($row2["STATUS"]){
                    $output.= "<td>".$row2["LETT"]."</td>";
               }else{
                    $output.= "<td>LETT</td>";    
               }    
          }
     }
     $output.= "</tr>";
}
$output.="</table>";  
     
 //display table
     echo      "$output"

?>
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13573784
OK, here I have replaced if($row=.... with while($row=....

I also assume that NUM in sqla matches a column(C1..C9) in sqlb!?

<?php
require 'db_connect2.php';

$result = mysql_query("SELECT * FROM sqlb");
$output= "<table border='1' align='center'>";
while($row = mysql_fetch_row($result)){
     $output.="<tr>";
     for($no=0;$no<9;$no++){
          $result2 = mysql_query("SELECT * FROM sqla WHERE NUM = '".$row[$no]."'");
          if($row2 = mysql_fetch_array($result2)){
               if($row2["STATUS"]=='1'){
                    $output.= "<td>".$row2["LETT"]."</td>";
               }else{
                    $output.= "<td>LETT</td>";    
               }    
          }else $output.= "<td>LETT</td>";  
     }
     $output.= "</tr>\n";
}
$output.="</table>";  
     
 //display table
     echo      "$output"

?>
0
 

Expert Comment

by:elhkwt
ID: 13573847
your assume is right, the NUM from the sqla processed  matches at least a column in sqlb..
but the table is not coming out
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13573950
This is very, very strange. THis is the same code, but without the $output variable, Now I use echo instead.

At lease you should see a lot of "LETT" columns now, If not, then I suspect that something else is wrong.


<?php
require 'db_connect2.php';

$result = mysql_query("SELECT * FROM sqlb");
echo "<table border='1' align='center'>";
while($row = mysql_fetch_row($result)){
     echo "<tr>";
     for($no=0;$no<9;$no++){
          $result2 = mysql_query("SELECT * FROM sqla WHERE NUM = '".$row[$no]."'");
          if($row2 = mysql_fetch_array($result2)){
               if($row2["STATUS"]=='1'){
                    echo "<td>".$row2["LETT"]."</td>";
               }else{
                    echo "<td>LETT</td>";    
               }    
          }else echo "<td>LETT</td>";  
     }
     echo "</tr>\n";
}
echo "</table>";  
     
?>
0
 

Expert Comment

by:elhkwt
ID: 13574001
nth has been shown beside the form used for input. is it the problem of the index.php which it links to?

<?php
//connect to database
include('db_connect2.php');
if (isset($_POST["num"]) && isset($_POST["lett"])) {

    $result = mysql_query("SELECT * FROM sqla WHERE NUM='" . $_POST["num"] . "' and LETT='" . $_POST["lett"] . "'");
    $match = mysql_num_rows( $result );
    if ( $match > 0 ) {
      mysql_query("UPDATE sqla SET STATUS='1' WHERE NUM='" . $_POST["num"] . "' and LETT='" . $_POST["lett"] . "'");
      echo ('Record Updated');}
      else echo('Try again');
}              
   include ('Hplaintable.php');  
?>

<form name="puzzleform" action="" method="POST" >
Number:<input type="text" name="num" id="num" value="" size="4">
Letter:<input type="text" name="lett" id="lett" value="" size="4">
    <input type="submit" name="submit" value="Submit">
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13574102
Could be.

You don't see any content in the table at all?

If the table is included, you could at least remove the database connection at the top of it.
0
 

Expert Comment

by:elhkwt
ID: 13574157
it only displays the form on the page. I have tried to link the index.php with another version of the plaintable code, it can display a table with that piece but the replacing NUM with LETT function is not working....

<?php

$result = mysql_query("SELECT * FROM sqlb");
$output= "<table border='1' align='center'>";
 
  for($i=0;$i<9;$i++){
   $row = mysql_fetch_row($result);
   
      $output.="<tr>";
     
    //replace function
    $result2 = mysql_query("SELECT * FROM sqla WHERE $STATUS=='1'");
 while( $row2 = mysql_fetch_array($result2)){
    for ($j=0;$j<9;$j++)
   $row[$j]=$LETT;}
   
    //get table
    for($k=0;$k<9;$k++){
    if ($row[$k]==0){
    $output.= "<td Class=f1>B".$row[$k]."</td>";}
    else
      $output.= "<td>".$row[$k]."</td>";}
   
     $output.= "</tr>";}
     $output.="</table>";  
     
 //display table
     echo       "$output"

?>
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13574213
One error in the code above is that STATUS has a $ in front of it.

it should be

$result2 = mysql_query("SELECT * FROM sqla WHERE STATUS=='1'");
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13574247
Could you try to do this in mysql and post the result

select * from sqla limit 10;
select * from sqlb limit 10;
0
 

Expert Comment

by:elhkwt
ID: 13574325
the $ is removed but it doesn't do the replace

select * from sqla limit 10;
NUM LETT STATUS
      25 d 0
      24 i 0
      23 j 0
      22 v 0
      21 f 0
      20 p 0
      19 r 0
      18 x 0
      17 e 0
      16 w 0

select * from sqlb limit 10;
 C1 C2 C3 C4 C5 C6 C7 C8 C9
      0 26 4 17 7 1 10 0 20
      4 0 2 0 24 0 6 0 7
      2 17 16 14 3 6 2 0 6
      9 0 19 0 24 0 13 0 8
      17 22 24 1 8 0 6 2 11
      6 0 8 0 0 0 19 0 20
      3 17 8 10 12 25 0 0 4
      0 0 17 0 0 0 0 0 14
      23 4 2 1 8 24 12 2 0
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13574415
Now, I have created your database tables and tried the example below. It works exactly as it should.

<?php

$output="";
$result = mysql_query("SELECT * FROM sqlb");
$output.= "<table border='1' align='center'>";
while($row = mysql_fetch_row($result)){
     $output.= "<tr>";
     
     for($no=0;$no<9;$no++){
             $sql = "SELECT * FROM sqla WHERE NUM = '".$row[$no]."'";
          $result2 = mysql_query($sql);
          if($row2 = mysql_fetch_array($result2)){
               if($row2["STATUS"]=='1'){
                    $output.= "<td>".$row2["LETT"]."</td>";
               }else{
                    $output.= "<td>LETT</td>";    
               }    
          }else $output.= "<td>LETT</td>";  
     }
     $output.= "</tr>\n";
}
$output.= "</table>";  
     
echo $output;
?>
0
 

Expert Comment

by:elhkwt
ID: 13574479
i can't get a clue now. it's not showing up on my page.......
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13574498
What do you see? Don't you see the table at all? Not even the surrounding borders?
0
 

Expert Comment

by:elhkwt
ID: 13574683
nth ...not even the borders
0
 
LVL 32

Accepted Solution

by:
Batalf earned 1600 total points
ID: 13574729
Then there's something else that's wrong. The border should have been there whether the queries were working or not.

You should check this:

1) Your error log - are there any errors there?
2) The path to the include file - is this include ('Hplaintable.php');  correct
3) Put in echo "Hello" at the top of the table file to see that it's included.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question