0

I am looking out for some kind of short code where i should not be repeating the column names in database and it should directly be inserted with respective column name index to array value . Below i have uploaded the image for understanding.

enter image description here

2 Answers 2

2

Use mysql_fetch_assoc() rather than mysql_fetch_row() and the array will be associative (using the column names as the key) rather than numeric.

$query = mysql_query("SELECT * FROM users_table WHERE User_ID = 1");

while ($r1 = mysql_fetch_assoc($query))
{
  echo $r1['User_ID'] . ': ' . $r1['First_Name'] . ' ' . $r1['Last_Name'] . '<br />';
}
Sign up to request clarification or add additional context in comments.

Comments

1

Check this:

$query = mysql_query( "SELECT * FROM users_table WHERE user_id=1;" );
$row = mysql_fetch_array( $query );
print_r( $row );

more about mysql_fetch_array on php.net

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.