/    Sign up×
Community /Pin to ProfileBookmark

mysql results from multiple rows in database table

I am running a mysql query with the code below but i cannot get the results from multiple rows in a table.
I echo the results and all i get is Array. Help will be appreciated. Thank you

The $row should echo all the fields under code1 in the table.

Thank you

[code=php]mysql_connect(‘localhost’, ‘u’, ‘C’);
mysql_select_db(‘u’);
//
$result = mysql_query(“SELECT code1 FROM codes”)
or die(mysql_error());
$row = mysql_fetch_assoc($result);
echo (“<center> <font color=#FF0000 face=Verdana size=2><b>$row</b></font>”);[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@themanronnieauthorFeb 17.2013 — the reason for the echo statement was to see exactly what the problem was. This is what i want done

To receive a variable from a form and test it against all the rows in a database column and if it finds one that corresponds to that row, then go to another page

The code is below
[code=php]

$code1=$_POST['code'];
mysql_connect('localhost', 'u', 'C');
mysql_select_db('u);
//
$result = mysql_query("SELECT code1 FROM codes")
or die(mysql_error());
$row = mysql_num_rows($result);

//
if ($row[0] =='$code1') {
include ("mynewpage.php");
} else {
echo ("<center> <font color=#FF0000 face=Verdana size=2><b>Invalid Code!</b></font>");
include("oldpage.php"); }
[/code]
Copy linkTweet thisAlerts:
@russelvasquezFeb 18.2013 — Hi, i think you should wrap your variable in curly brace {}.

Try my example.

<?php

//your connection info

include_once ("includes/connection.php");

?>

<html>

<head>


<title>

</title>
</head>

<?php
$query = "Select menu_name from menu_rf";
$result = mysql_query($query);

$arr = array();
while($rows = mysql_fetch_array($result)){
echo "<center><font color=#FF0000 face=Verdana size=2><b>{$rows['menu_name']}</b></font></center>";

}

?>

</html>

Note: I already test and it works. I hope it helps you.
Copy linkTweet thisAlerts:
@NogDogFeb 18.2013 — $row is an associative array, so you need to access each column of the result row (even if it's only one column) as [FONT=Courier New][B]$row['code1'][/B][/FONT].

The typical way to output all results is to use a while() loop:
[code=php]
echo "<ul>n";
while($row = mysql_fetch_assoc($result) {
echo "<li>".$row['code1']."</li>n";
}
echo "</ul>n";
[/code]
×

Success!

Help @themanronnie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...