PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
gphp
Forum Commoner
Posts: 29 Joined: Sun Feb 17, 2008 1:40 pm
Post
by gphp » Sun Feb 17, 2008 1:43 pm
I am loading data from database but I get the data twice!?
***** PLEASE USE Code: Select all
WHEN POSTING *****[/color]
[syntax=php]if (is_array($fetch)){
foreach ($fetch as $data){
print "<table><tr><td>".$data."</td></tr></table>";
}
}[/syntax]
Display:
string1
string1
string2
string2
string3
string3
Why it would do that?
Thanks.
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sun Feb 17, 2008 2:05 pm
What does the code where you load $fetch look like? Do this to see what is in fetch:
Code: Select all
echo '<pre>' . print_r($fetch, 1) . '</pre>';
(#10850)
gphp
Forum Commoner
Posts: 29 Joined: Sun Feb 17, 2008 1:40 pm
Post
by gphp » Sun Feb 17, 2008 2:16 pm
Well, this is the ouput now!?
Code: Select all
Array
(
[0] => string1
[tablecolumn1] => string1
[1] => string2
[tablecolumn2] => string2
[2] => string3
[tablecolumn3] => string3
)
This is how I am accessing the db:
Code: Select all
$DB->sql_connect('host', 'user', '', 'dabatasename');
$query = $DB->query("SELECT * FROM tablename WHERE tablecolumn2='username'");
$fetch = $DB->fetch_row($query);
gphp
Forum Commoner
Posts: 29 Joined: Sun Feb 17, 2008 1:40 pm
Post
by gphp » Sun Feb 17, 2008 3:01 pm
RESOLVED
printf ("ID: %s BLOB1: %s BLOB2: %s", $fetch[0], $fetch["1"], $fetch[2]);
No need for "foreach"!
Thanks