<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Sat May 25, 2013 9:18 am by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Sat May 25, 2013 9:18 am</pubDate>
  <lastBuildDate>Sat May 25, 2013 9:18 am</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>Re: php/mysql array problem</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=6034#6034</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=2420'&gt;huwgreen&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Wed Aug 03, 2005 8:41 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Many thanks bigbee, I've finally got it sorted. Sorry I haven't replied sooner, but I'm currently doing more things at once than I should!&lt;br /&gt;
Once again, many thanks</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=6034#6034</comments>
                                        <author>huwgreen</author>
                                        <pubDate>Wed Aug 03, 2005 8:41 am</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=6034#6034</guid>
                                      </item>
                                      <item>
                                        <title>Re: php/mysql array problem</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=5968#5968</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=1442'&gt;bigbee&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Aug 01, 2005 9:19 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      First of all mysql_fetch_assoc array returns a single row of your result your construction should be a little bit like this:&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
int $foo=0;&lt;br /&gt;
while &amp;#40;$result = mysql_fetch_assoc&amp;#40;$userid&amp;#41;&amp;#41; &amp;#123;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;$row&amp;#91;$foo&amp;#93;=$result&amp;#91;0&amp;#93;; //or result&amp;#91;&amp;quot;userid&amp;quot;&amp;#93;, there the associative part of fetch_assoc comes into play&lt;br /&gt;
&amp;nbsp; &amp;nbsp;$foo++;&lt;br /&gt;
&amp;#125;&lt;br /&gt;
//this construct a row containing the userids&lt;br /&gt;
foreach &amp;#40;$row as $membid&amp;#41;&lt;br /&gt;
&amp;#123;&lt;br /&gt;
echo &amp;#40;&amp;quot;The ids are&amp;#58;&amp;lt;br&amp;gt;$membid&amp;lt;br&amp;gt;&amp;quot;&amp;#41;;//if $membid is an unique number this will print only one id, if several accounts have the same memid, this will be printed the amount of users with the same memid&lt;br /&gt;
&amp;#125; &lt;br /&gt;
//to print all the elements&amp;#58;&lt;br /&gt;
for&amp;#40;$bar=0;$bar&amp;lt;count&amp;#40;$row&amp;#41;;$bar++&amp;#41;&lt;br /&gt;
&amp;#123;&lt;br /&gt;
echo &amp;quot;memberid = &amp;quot;.$row&amp;#91;$bar&amp;#93;.&amp;quot;&amp;lt;br&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;#125;&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
The mysql_fetch_assoc is handy if you extract your data and want access to them by the row-name. eg. Say $result is the returned result of your query on a table containing &quot;name&quot; and &quot;age&quot;&lt;br /&gt;
$data=mysql_fetch_row($result); will be an array on which your data can be accessed as $data[0] and $data[1]&lt;br /&gt;
$data=mysql_fetch_assoc($result); will be an array on which your data can be accessed as $data[&quot;name&quot;] and $data[&quot;age&quot;]&lt;br /&gt;
&lt;br /&gt;
I hope this will help you solve the problem... Let us/me know!&lt;br /&gt;
&lt;br /&gt;
grtz&lt;br /&gt;
&lt;br /&gt;
bb</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=5968#5968</comments>
                                        <author>bigbee</author>
                                        <pubDate>Mon Aug 01, 2005 9:19 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=5968#5968</guid>
                                      </item>
                                      <item>
                                        <title>php/mysql array problem</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=5932#5932</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=2420'&gt;huwgreen&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Aug 01, 2005 10:22 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      &lt;span style=&quot;font-weight: bold&quot;&gt;I've just started working with php and mysql, and seem to have fallen at the first hurdle. I have a table  called authority holding userids and level of access to the database. If I run the following code directly on the mysql server it displays all the userids and the total row count&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
select userid from authority;&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
However, if I run it through php, and try to use mysql_fetch_array/assoc/result, and then try to display the result all that is returned is the first element of the array. This happens whatever I use to display the result, foreach, list, echo $varname[0]...[n].&lt;br /&gt;
mysql_num_rows returns the correct row count.&lt;br /&gt;
I've been trying to see where I've made a mistake for a couple of days now and I'm not getting anywhere.&lt;br /&gt;
The relevant php is:&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
$userID_sql = &amp;quot;select userID from authority&amp;quot;;&lt;br /&gt;
$userID = mysql_query &amp;#40;$userID_sql,$conn&amp;#41;; //$conn is the connection index&lt;br /&gt;
$allowed = mysql_fetch_assoc&amp;#40;$userID&amp;#41;;&lt;br /&gt;
foreach &amp;#40;$allowed as $membid&amp;#41;&lt;br /&gt;
&amp;#123;&lt;br /&gt;
echo &amp;#40;&amp;quot;The ids are&amp;#58;&amp;lt;br&amp;gt;$membid&amp;lt;br&amp;gt;&amp;quot;&amp;#41;;&lt;br /&gt;
&amp;#125;&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
I'm using php/mysql/apache that is installed with SLES9&lt;br /&gt;
I hope someone can help.&lt;br /&gt;
 Many thanks in advance&lt;br /&gt;
John&lt;/span&gt;</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=5932#5932</comments>
                                        <author>huwgreen</author>
                                        <pubDate>Mon Aug 01, 2005 10:22 am</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=5932#5932</guid>
                                      </item></channel></rss>