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
Solved

How does mysql_fetch_assoc store rows from a query?

Posted on 2008-10-24
1
606 Views
Last Modified: 2013-12-13
I am using Dreamweaver's built in functionality to create a drop down list from a MySQL query.  The problem I have is that if I try to duplicate the list on the same page, only the first instance is filled with info from the query.  It may have something to do with the way "mysql_fetch_assoc" counts through the rows.  Can someone please explain how this works and how I can create multiple lists from the one query?  Thanks.
// The following is a couple snippets from my page:
 
mysql_select_db($database_gw2000Connect, $gw2000Connect);
$query_getAllNames = "SELECT * FROM users";
$getAllNames = mysql_query($query_getAllNames, $gw2000Connect) or die(mysql_error());
$row_getAllNames = mysql_fetch_assoc($getAllNames);
$totalRows_getAllNames = mysql_num_rows($getAllNames);
 
 
<select name="entryToApply">
  <?php do { ?>
  <option value="<?php echo $row_entriesToApply['invoiceNum']; ?>">
    <?php echo $row_entriesToApply['invoiceNum']; ?>
  </option>
  <?php } while ($row_entriesToApply = mysql_fetch_assoc($entriesToApply)); ?>
</select>

Open in new window

0
Comment
Question by:CheeserTheAverage
1 Comment
 
LVL 3

Accepted Solution

by:
raminhos earned 500 total points
ID: 22801384
Try:
<?
 
mysql_select_db($database_gw2000Connect, $gw2000Connect);
$sql = "SELECT * FROM users";
$qry = mysql_query($sql);
while ($row = mysql_fetch_array($qry)){
 
  // CREATE ARRAY WITH DATA
  $entries[] = $row_entriesToApply['invoiceNum'];
 
}
 
// FIRST SELECT
 
$select = "<select name='entryToApply'>";
foreach ($entries as $a){
  $select .= "<option value='$a'>$a</option>";
}
$select .= "</select>";
 
 
 
// SECOND SELECT
 
$select1 = "<select name='entryToApply2'>";
foreach ($entries as $b){
  $select1 .= "<option value='$b'>$b</option>";
}
$select1 .= "</select>";
 
 
/// and continue...
 
 
?>

Open in new window

0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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