Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing mysql_fetch_assoc and mysql_result together?
    primarykey
    data
    text
    <p>I am having great trouble trying to use <code>mysql_fetch_assoc</code> and <code>mysql_result</code> together in the same PHP script. </p> <p>Originally (when not utilizing the <code>mysql_result</code> function) I was getting the required database values using a combination of <code>mysql_query</code> and <code>mysql_fetch_assoc</code> and everything was fine. Then i added 2 lines into my code to obtain certain ‘title’ field values using <code>mysql_result</code>.</p> <p>Now if i run my script as it is below i will only receive 1 result even though there are 2 result. Then if i move my <code>do/while</code> loop up so that it is between the other 2 blocks of code (<code>mysql_fetch_assoc</code> and <code>mysql_result</code> lines) i will receive the desired 2 results.</p> <p>I need my loop to come after the <code>mysql_result</code> section so putting the loop before it is not an option.</p> <pre><code>// connect to DB and get values mysql_select_db($database, $mywebsite); $query_not_related_before = "SELECT * FROM table limit 2"; $not_related_before = mysql_query($query_not_related_before, $ mywebsite); $row_not_related_before = mysql_fetch_assoc($not_related_before); // Extract just the results from the title field (the problem area!) $before_essayid4 = mysql_result($not_related_before,0, 'title'); $before_essayid5 = mysql_result($not_related_before,1, 'title'); // Display results etc do { echo "&lt;br /&gt;".$row_not_related_before['title']."&lt;br /&gt;";} while ($row_not_related_before = mysql_fetch_assoc($not_related_before)); </code></pre> <p>Plase help,</p> <p>Many thanks,</p> <p>David</p>
    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.
    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