Problems with adding a link to one position in a 'foreach' loop, please help


Posted on 16th Feb 2014 07:03 pm by admin

Hello!

Iam pretty new to programming and I wanna create a table with users from an array. It works just fine but in one table row I wanna add a link to it so I can click on the username to edit it later. This is my code right now:

Did you know?Explore Trending and Topic pages for more stories like this.
Code: $keys = mysql_query("SELECT * FROM users", $connection);
confirm_query($keys);
$result = mysql_query("SELECT * FROM users", $connection);
if (!$result)
confirm_query($keys);

echo "<table id="usertable">";
echo "<tr id="usertablemain">";
$a = array_keys(mysql_fetch_assoc($keys));
foreach($a as $b) { echo "<td>" . $b . "</td>";}
echo "</tr>";
while ($rows = mysql_fetch_assoc($result))
{
echo "<tr>";
foreach ($rows as $row)
{

echo "<td>".$row."</a>"."</td>";
}
echo "</tr>";
}
echo "</tr>";
echo "</table>";

I tried to nest a IF statement but it always give in some way true and all positions in the table get a <a href> tag. The array contains a position called 'username' which is in the second row. Please help me out
No comments posted yet

Your Answer:

Login to answer
222 Like 35 Dislike
Previous forums Next forums
Other forums

insert/update functions for mysql, what do you think?
I am working on two really simple functions that automatically generate (and execute) insert and upd

Floating Point Precision Loss
I'm writing a program to draw a three-dimensional cube (with a corner cut off) without using any 3D

Day of week
I am using PHP version 5.0.5
I have a varaible ($DATE (date format yyyy-mm-dd)) that is being inc

SQL query not working well
Hi,
I made a small table with 5 rows and want to make them an sql consult using rownum

A Few Questions
Hi, I want to ask a few questions that I can't seem to find..

1) I'm creating a "shortcu

Combining refCursors and Summing
Given the following DDL:

CREATE TABLE FOODSALESTEST ("WEEKNBR" NUMBER, "ST

New to PHP and just trying to understand a little code.
I hope I'm not annoying anyone or breaking the rules but I was wondering about this bit of code righ

Career Change into SAP
Hai
I am sajesh ,did my diploma in Mechatronics i have a 4 years of experience in

How to pass parameter to tag query?
Hi,
I want to get the value of a tag at a specific time (like 10/27/09 15:29:59), I need to giv

What are causes of a connection-timeout with fopen()?
Hello! Here is the situation: The server I host my website on just upgraded it's PHP build from 4.4.

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash