获取SQL记录

时间:2013-01-13 16:47:35

标签: php mysql database fetch

啊,我写了一个脚本,但我已经忘记了如何获取MySQL记录......所以......我遇到了这个问题

资源ID#X

$QUERY = "SELECT id FROM WORKING TABLE VARIABLE WHERE username='WORKING USERNAME VARIABLE' and password='WORKING PASSWORD VARIABLE'";
$QUERY1 = mysql_query($QUERY);
$myusername = $QUERY1
echo $myusername;

我知道我必须在这里取。我在互联网上尝试了很多方法。但它们都不起作用。通过我得到NOTHING的结果。请帮忙吗?

没有这个代码......我得到了所有东西,比如密码,电子邮件和用户名(alpha版本)。

4 个答案:

答案 0 :(得分:1)

试试这个

  $QUERY = "SELECT * FROM WORKING TABLE VARIABLE WHERE username='WORKING USERNAME VARIABLE' and password='WORKING PASSWORD VARIABLE'";
   $QUERY1 = mysql_query($QUERY);
 while($row = mysql_fetch_array($QUERY1))
  {
   $row['username'] =  $myusername;
    echo $row['username'];
  }

答案 1 :(得分:0)

试试这个:

$QUERY = "SELECT id FROM WORKING TABLE VARIABLE WHERE username='WORKING USERNAME VARIABLE' 
and password='WORKING PASSWORD VARIABLE' ";
$QUERY1 = mysql_query($QUERY);

while($row = mysql_fetch_array($QUERY1))
  {
  echo $row['id'];//you are selecting id not username
  }

答案 2 :(得分:0)

尝试:

echo $myusername[0]['id'];

如果你想实际获取这样的结果,我会使用mysqli_fetch_object。

答案 3 :(得分:0)

我已经写了代码来获取每条记录,但是只能获取一条记录

<div class="container" style="margin-top:10px"> 
<div class="container-fluid">
<div class="table-responsive">
<div style="height:300px; width:1800px" class="scrollable">
<table id="1" class="table" border="2">
      <tr style="text-align:center">
        <th>ID</th>
        <th>Name</th>
        <th>Phone</th>
        <th>Email</th>
        <th>Address</th>
        <th>City</th>
        <th>State</th>
        <th>Product Name</th>
        <th>Pincode</th>
        <th>Date</th>
        <th>Status</th>
        <th>Agent</th>
        <th>Order From</th>
        <th>Note</th>
       </tr>
       <tr style="width:auto; line-height:10px;" valign="top">
      <?php 
      $sr=1;
      $data=mysqli_query($conn,"Select * from `testing` Where `orderFrom`='".$q."'");
      while($row=mysqli_fetch_array($data))
      {
      ?> 
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['id'];  ?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['name'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['phone'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['email'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['address'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['city'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['state'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['orderid'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['pincode'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['date'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['status'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['agent'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>"><?php echo $row['orderFrom'];?></td>
        <td style="font-size:<?php  echo $fonts; ?>">
        <div class="container">
        <div class="row">
        <div class="col-md-6">
<div id="form">
   <input type="text" name="mynotes" id="mynotes">
   <input type="hidden" id="mob" value="<?php echo $row['phone']; ?>"/>

   <button type="submit1"  id="submit1" name="submit1" onClick="loadVariables()">Go</button>
  </div>
  </div>
   <div class="col-md-6">
<textarea style="overflow:scroll; height:50px; width:170px">
<?php 
$sql="Select * from `order`.`notes` WHERE `phone`='".$row['phone']."'";
$query=mysqli_query($conn,$sql);

while($row1=mysqli_fetch_array($query))
{
  echo $row1['notes']; 
}
?>
</textarea>
 </div>
  </div></div>
     </td>
       </tr>
       <?php  
      $sr`enter code here`=$sr+1;
      }
      ?> 
  </table>
  </div>
</div>
</div>