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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    A mysql_fetch_array error :(

    Hey all.
    I am having some trouble with a mysql_fetch_array statement in a script (bellow) that should make news from a message board appear on the screen.
    PHP Code:
    <?php
    include("nav.php");
    ?>
        <td width="610" valign="top" border="1">
          <table width="610" cellpading="0" cellspacing="0" align="left" border="0">
            <tr>
              <td width='610' height='9' bgcolor='#000000' valign='top'></td>
            </tr>
            <tr>
              <td width='610' height='13' background='images/index_06.gif' valign='top'></td>
            </tr>
            <tr>
              <td>
                <table width='610' border='0' rowspan='0' background='images/index_08.gif' >
    <?php
    include("connections/forum.php");
    $get mysql_query("SELECT * FROM `threads` WHERE `type` = 'announcement' ORDER BY id");
    while (
    $array mysql_fetch_array($get)) {
      
    $poster $array['poster'];
      
    $get2 mysql_query("SELECT * FROM users WHERE username='$poster'");
      while (
    $array2 mysql_fetch_array($get2)) {
        echo 
    "<tr>
                    <td width='15%'><b><u>$array[poster]</u></b></a></td>
                    <td width='84%' align='right'>$array[posttime]</td>
                  </tr>
                  <tr>
                    <td align='center' valign='middle'>
                    <img src='images/admin.jpg' alt='' border='2' width='80' height='80' />
                  </td>
                  <td width='84%' valign='top'><b><u>$array[title]</u></b><br /><br /><br /><br />\n
                  $array[message]<br /><br />
                  ________________________________________________________________
                  </td>
                </tr>
    "
    ;
      }
    }
    ?>
              </table>
            </td>
           </tr>
           <tr>
             <td width='610' height='13' background='images/index_06.gif' valign='top' border='1'></td>
          </tr>
        </td>
      </table>
      </td>
      <td width="10" height="542" bgcolor="#000000" valign="top" border="1"></td>
      <td width="127" height="2" colspan="0" valign="top" background="images/index_04.gif" rowspan="16" align="top">
          <table cellpading="0" cellspacing="0" align="top" border="1">
            <tr>
              <td valign="top" rowspan="2" border="1">
              <?php
              
    if (!$_SESSION['userid']) {
              
    ?>
              <center><b>Log in</b></center>
              <form method="POST" action="login2.php">
              Username :<br />
              <input type="text" name="username" title="username" id="username" size="15" /><br />
              Password :<br />
              <input type="text" name="password" title="password" id="password" size="15" />
              <input type="submit" value="Log in" /><input type="reset" value="reset" />
              </form>
              <?php
              
    } else {
              
    ?>
              Welcome back : <br /><b><?php echo $_SESSION[username]; ?></b><br /><br />
              <img src="<?php echo $_SESSION[avatar]; ?>" alt="" border="2" /><br /><br />
              <a href="modifyprofile.php?id=<?php echo $_SESSION[userid]; ?>">
              Modify your profile</a>
              <?php
              
    }
              
    ?>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    </body>
    </html>
    Line 21 is where the error is, it says it isn't a valid mySql ressource
    Line 21 is :
    $get2 = mysql_query("SELECT * FROM users WHERE username='$poster'");

  • #2
    New Coder
    Join Date
    May 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would try this:
    $get2 = "SELECT * FROM users WHERE username='$poster'";

    I don't use mysql_query(); for any of my select statements. But I am fairly new at this game.

    Cheers,

    Chris

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You have to use mysql_query() -- that's how the statement gets sent to the database. Without it, you've just got a string variable floating around. I do prefer, though, to keep my statements in a separate variable and send that to mysql_query() -- that way, it's easy to echo the query to see exactly what you're sending.

    For some reason, your query is failing, so $get2 is being set to FALSE instead of to a resource. Try echoing your query to see what's being sent and adding 'or die(mysql_error())' to the end of your mysql_query() call to get MySQL's error message regarding the query.

  • #4
    New Coder
    Join Date
    May 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh Geez. I didn't even realize what I posted haha.

    I always place SELECT * Blah Blah in a variable then use mysql_query();

    Like this:
    Code:
    $sql = "SELECT CourseName, TeacherName, NotesTitle, FileName
    		From Notes
    		Where CourseName = '$CourseName'
    		Order by NotesTitle Asc";
    
    $result = mysql_query($sql);


  •  

    Posting Permissions

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