Nothing Appears

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
weenoid
Forum Newbie
Posts: 1
Joined: Fri Jan 03, 2003 3:59 pm
Location: Manchester

Nothing Appears

Post by weenoid »

Hi, I am quite new to SQL and I am currently just playing around with a few codes. The code below is one that I have written and i've checked that the databases are set up correctly and everything's fine. The problem is that when I open the page nothing appears. This is the code:

<?php
$sql = "connect [localhost]";
$result = $sql = "list_tables [exemu_files]";
$i = 0;
while ($i < $sql = "num_rows [$result]") {
$tb_names[$i] = $sql = "tablename [$result, $i]";
echo $tb_names[$i] . "
";
$i++;
}
?>

Any ideas as to what could be wrong? Any help would be much appreciated.
DaiWelsh
Forum Commoner
Posts: 36
Joined: Wed Jan 08, 2003 9:39 am
Location: Derbyshire, UK

Post by DaiWelsh »

Hmm, seems like pretty much everything is wrong with it to me, in fact might you have done a search and replace on "mysql_" with "$mysql = " at some point because that would at leats make it look half familiar.

I am not in a position to test it but something like

<?php
mysql_connect (localhost);
$result = mysql_list_tables (exemu_files);
$i = 0;
while ($i < mysql_num_rows [$result]) {
$tb_names[$i] = mysql_tablename [$result, $i];
echo $tb_names[$i] . "< b r >";
$i++;
}

might at least be closer to what you are trying to do?

HTH,

Dai
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Hmm, seems like pretty much everything is wrong with it to me, in fact might you have done a search and replace on "mysql_" with "$mysql = " at some point because that would at leats make it look half familiar.
Lol !!!!!!

Be nice. At least he gave it a try which is a lot better than "write this for me".

Cheers,
BDKR
DaiWelsh
Forum Commoner
Posts: 36
Joined: Wed Jan 08, 2003 9:39 am
Location: Derbyshire, UK

Post by DaiWelsh »

Oops was me harsh? <slap> :oops:
User avatar
DaZZleD
Forum Commoner
Posts: 38
Joined: Tue Jan 07, 2003 5:39 am

Post by DaZZleD »

teehee
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

DaiWelsh wrote:because that would at least make it look half familiar
:lol: It was an interesting try and definitely better than saying 'write me some code'.

weenoid - the likely reason that nothing happened when you wrote the code is because you put the attempted function calls into quotes and used square brackets instead of parenthesis to add the arguments. This meant that PHP considered them strings and not function calls. The following should begin to show results ($user and $pass should be substituted by your username and password for the MySQL database - the default is 'root' and nothing for the password):

Code: Select all

<?php 
@mysql_connect('localhost', $user, $pass) or die(mysql_error());
@$result = mysql_list_tables('exemu_files') or die(mysql_error()); 

while ($row = mysql_fetch_row($result)) { 
    $tb_names[] = $row[0]; 
    echo $row[0].'<br />'; 
} 
?>
You should probably also read up on the MySQL functions available in PHP and how to use them:
http://www.php.net/manual/en/ref.mysql.php

Mac
Post Reply