help with php pages...

pastajon66@juno's picture

They have: 9 posts

Joined: Jan 2006

i have copied and pasted a few php scripts
that is the length of my php experience
i mostly use golive for authoring

i am currently hoping to finish someone else's website for them and they designed it in php
most of what i need to do is add images and edit text
i also need to add something to the navigation

can anyone recommend a shareware program or php resource that could help me finish this site with out screwing it up?

is this over my head OR can i learn this with some effort?

the site is fmlytree.com for reference

olo brockhouse of loamsdown
park city, ut

He has: 21 posts

Joined: Jan 2006

Well you can use many many softwares for this. Try PHP Designer 2006 (is free) or you can try Dreamweaver which is more professional looking. And to insert images you just use simple HTML, that's it.

Admin and CEO of StackedTech and Planet Diaz

pastajon66@juno's picture

They have: 9 posts

Joined: Jan 2006

are you saying that i can edit in html without messing up the php scripting through out the site?

timjpriebe's picture

He has: 2,667 posts

Joined: Dec 2004

Absolutely. All the PHP code should be in sections starting with

<?php
and ending with
?>

As long as you stay out of those sections, you won't mess up the PHP at all. Of course, at some point, you may have to adjust something in those sections. There's no real way to tell ahead of time.

pastajon66@juno's picture

They have: 9 posts

Joined: Jan 2006

i get this warning message on the bottom of a page that i created within the MySQL database:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site306/fst/var/www/html/samples_body.php on line 22

here is line 22:
while($myrow = mysql_fetch_array($result))

what could be wrong?

olo brockhouse of loamsdown
park city, ut

timjpriebe's picture

He has: 2,667 posts

Joined: Dec 2004

I'm not sure without seeing the code, but I'm pretty sure that line should be fixed like this:

while(@myrow = mysql_fetch_array($result))

Again, it's nearly impossible to tell if that's the only thing wrong. Often when errors like that are thrown, the mistake may not be on the actual line that PHP thinks it is on. A classic example is where the line of code before is missing a semicolon at the end.

pastajon66@juno's picture

They have: 9 posts

Joined: Jan 2006

tim,
thanks for the suggestion
i tried it without success
here is the code for that page:

<?php
// load the configuration file.
include("config.php");
    if (@
$_REQUEST['id'] == ""){
   
$category = 1;
    } else {
   
$category = $_REQUEST['id'];
    }
       
$result = mysql_query("SELECT * FROM samples_tbl WHERE id='$category' ",$connect);
       
//lets make a loop and get all news from the database
       
while($myrow = mysql_fetch_array($result))
             {
//begin of loop
               //now print the results:
              
$section = $myrow['category'];
               echo
"<div id=\"copy\">";
               echo
$myrow['text'];
               echo
"</div>";
             }
//end of loop
       
$result = mysql_query("SELECT * FROM img_tbl WHERE category='$section' ORDER BY name",$connect);
       
//lets make a loop and get all news from the database
       
echo "<div class=\"container\">";
        while(
$myrow = mysql_fetch_array($result))
             {
//begin of loop
               //now print the results:
              
echo "<div class=\"float\">";
               echo
"<a href=\"display.php?id=".$myrow['name']."\"><img src=\"images/mid_tree_thumbs/".preg_replace('/\s+/', '', $myrow['name']).".jpg\" alt=\"".$myrow['name']."\" height=\"100\" width=\"100\"><br>";
               echo
"<p>".$myrow['name']."</p></a>";
               echo
"</div>";
             }
//end of loop
       
echo "</div>";
       
mysql_close();
?>

olo brockhouse of loamsdown
park city, ut

timjpriebe's picture

He has: 2,667 posts

Joined: Dec 2004

What info is in config.php? It should have $connect defined.

She has: 31 posts

Joined: Jan 2006

The error is because this query:

mysql_query("SELECT * FROM img_tbl WHERE category='$section' ORDER BY name",$connect);

..is failing. It can't be due to the connection in config.php failing, otherwise the previous mysql_query on line 11 would also fail.

Therefor it's a problem with your mysql database. The three possible problems are:

There is no table called img_tbl
There is no row called category
There is no row called name

P.S. what Tim suggested is incorrect:

while($myrow = mysql_fetch_array($result))

Will fetch a row from the result and put it in $myrow whereas..

while(@myrow = mysql_fetch_array($result))

Will do nothing, it needs to be assigned to a variable. What he meant to suggest was:

while($myrow = @mysql_fetch_array($result))

Which will do exactly the same thing as it already does, but it wont issue an error message.

timjpriebe's picture

He has: 2,667 posts

Joined: Dec 2004

Actually, I suggested what I meant to suggest, but was thinking of Perl, not PHP. Laughing out loud One of the pitfalls of working simultaneously in too many languages.

She has: 31 posts

Joined: Jan 2006

I hear ya, I remember switching to JavaScript from PHP and spending hours wondering why my <? tags weren't working.

pastajon66@juno's picture

They have: 9 posts

Joined: Jan 2006

i applied the @ to the code and whoala, it is fixed!
thanks again for helping me out!

They have: 238 posts

Joined: May 2002

Technicially the ampersand just surpresses the error message being generated by the function. You are much better off fixing the problem instead of hiding it.

The usual reason for the error message "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in" is that the sql query is malformed (contains an error, etc). You can find the error in your query by appending an "or clause" to the mysql_query function to display the error and terminate the execution of the script.

$result = mysql_query("SELECT * FROM samples_tbl WHERE id='$category' ",$connect) or die( mysql_error() );

Give that a whirl.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.