writing functions
Posted: Wed Jan 22, 2003 3:33 am
Hi
As you'll be able to tell from the following message I'm a complete novice at PHP.
I have just managed to make my first script that write information to a mySQL database and I can also retrieve it. In the table for this database is information for a menu bar and what I'd like to do is for the script to place all buttons in a list. I have tried to do this in a function. Heres my code (dont laugh)
<?php
include_once("connection/connection.php");
$result = mysql_query("SELECT * FROM mainMenu",$db);
$imageURL = mysql_result($result,0,"image");
$imageALT = mysql_result($result,0,"alt");
$imageLink = mysql_result($result,0,"link");
function writeMenu($imageLink, $imageURL, $imageALT)
{
$num_rows = mysql_num_rows($result);
{
printf('<table width="136" border="0" cellspacing="0" cellpadding="0">');
if ($num_rows > 0){
for($i = 0; $i < $num_rows; $i++)
printf('<tr> <td width="857" height="25">');
printf("<a href=\"$imageLink\"><img src=\"$imageURL\" width=\"136\" height=\"25\" alt=\"$imageALT\"> </a> \n");
printf('</tr> <tr>');
}
}
}
?>
and i call up the fuction with
<?php
writeMenu()
?>
and get back the error
Missing argument 1(to 3) for writemenu() in public_html/index.php on line 13
which is this line
function writeMenu($imageLink, $imageURL, $imageALT)
and the error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in public_html/index.php on line 15
which is
$num_rows = mysql_num_rows($result);
any clues on what I have done would be gratefully received. Thanks.
Deej
As you'll be able to tell from the following message I'm a complete novice at PHP.
I have just managed to make my first script that write information to a mySQL database and I can also retrieve it. In the table for this database is information for a menu bar and what I'd like to do is for the script to place all buttons in a list. I have tried to do this in a function. Heres my code (dont laugh)
<?php
include_once("connection/connection.php");
$result = mysql_query("SELECT * FROM mainMenu",$db);
$imageURL = mysql_result($result,0,"image");
$imageALT = mysql_result($result,0,"alt");
$imageLink = mysql_result($result,0,"link");
function writeMenu($imageLink, $imageURL, $imageALT)
{
$num_rows = mysql_num_rows($result);
{
printf('<table width="136" border="0" cellspacing="0" cellpadding="0">');
if ($num_rows > 0){
for($i = 0; $i < $num_rows; $i++)
printf('<tr> <td width="857" height="25">');
printf("<a href=\"$imageLink\"><img src=\"$imageURL\" width=\"136\" height=\"25\" alt=\"$imageALT\"> </a> \n");
printf('</tr> <tr>');
}
}
}
?>
and i call up the fuction with
<?php
writeMenu()
?>
and get back the error
Missing argument 1(to 3) for writemenu() in public_html/index.php on line 13
which is this line
function writeMenu($imageLink, $imageURL, $imageALT)
and the error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in public_html/index.php on line 15
which is
$num_rows = mysql_num_rows($result);
any clues on what I have done would be gratefully received. Thanks.
Deej