|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Partly Working
I am trying to do a query on a table an present the results. I have got it working just fine for the first set of results but the anything after that doesn't appear to be working. Here is the code:
PHP Code:
Does anyone have any idea why the 2nd and 3rd iteration of my request are not processing? There are records in there with those categories. Thanks in advance for your help. Andy |
|
#2
|
||||
|
||||
|
you may want to try:
PHP Code:
__________________
CHornJr "One day I'll know what I am doing" ![]() My Blog Suanhacky Lodge #49 Rebel Squadrons |
|
#3
|
|||
|
|||
|
Could you please be more specific in how you are suggesting I apply this? Thank you so much for your time.
Andy Quote:
|
|
#4
|
||||
|
||||
|
basically your dropping the $num=mysql_num_rows($result), $i<$num and the @ symbol from in front of the array creation function
PHP Code:
Also, double check the spelling of the column names compared to how you have them when you call them in the variables. I know I have many times misspelled in one or the other, or capitalized when I didn't want to Three more suggestions
|
|
#5
|
|||
|
|||
|
OK, I have tried using the mysql_fetch_assoc function and my code looks like this:
PHP Code:
The problem is, on the last iteration it is not printing out the </a> tag and you can see how it is being displayed at: (URL address blocked: See forum rules)/html/links3.php Also, can you enlighten me as to how I would leave the connection open and also how I would put the results into a function. Thanks for your help and patience. I am coming back to this out of necessity after a long time of not using it and it is a little frustrating. Thanks, Andy |
|
#6
|
|||
|
|||
|
OK, found the source of the problem. Got it up and running perfectly now.
Thanks for your help. If you could answer the last couple of questions regarding connecting and putting the results into a function I would appreciate it. Andy |
|
#7
|
||||
|
||||
|
I hope that isn't the actual username and password for the database, if it is I would recommend changing it now as well as any other passwords that are similar to it
to keep the connection open just erase the mysql_close() function the next question is a PHP question so the mods may end up moving the thread there are several ways to make it into a function (or class) but the simplest way would be: PHP Code:
There are some other ways of setting up the function, but using your example this seems to be the simplest way of setting it up. |
|
#8
|
|||
|
|||
|
Thanks so much for your help on this. That indeed was my actual password and it has been changed.
|
|
#9
|
|||
|
|||
|
If you look at:
http://industrialodorcontrol.com/html/links2.php you will see that as I have set this up it is not working. I have the function at the top in a seperate file named function_file.php, is that correct? I then have put php tags around the rest. It is not working properly and I'm at a loss as to why. It appears to be looking for a file called function_filephp however there is not reference to that file here anywhere. Here is the code from my page: [PHPNET] <?php //Engineers.php include (function_file.php); $sql="SELECT * FROM links WHERE category = 'Engineers'"; function_name($sql);?> </span></td> </tr> <tr> <td colspan="2"><div align="left"><span class="style2"><a name="Wastewater" id="Wastewater"></a>Wastewater </span></div></td> </tr> <tr> <td> </td> <td><span class="style1"> <?php //Wastewater.php include (function_file.php); $sql="SELECT * FROM links WHERE category = 'Wastewater'"; function_name($sql); ?> </span></td> </tr> <tr> <td colspan="2"><span class="style2"><a name="Contractors" id="Contractors"></a>Contractors</span></td> </tr> <tr> <td> </td> <td><span class="style1"> <?php //Contractors.php include (function_file.php); $sql="SELECT * FROM links WHERE category = 'Contractors'"; function_name($sql); ?> </span></td> </tr> <tr> <td colspan="2"><div align="left"><span class="style2">Buyer's Guides</span></div></td> </tr> <tr> <td> </td> <td><span class="style1"> <?php //Buyers Guides.php include (function_file.php); $sql="SELECT * FROM links WHERE category = 'Buyers Guides'"; function_name($sql);?> </span></td> </tr> <tr> <td colspan="2" class="style2">General</td> </tr> <tr> <td> </td> <td><span class="style1"> <?php //General.php include (function_file.php); $sql="SELECT * FROM links WHERE category = 'General'"; function_name($sql);?> </span></td> </tr> <tr> <td colspan="2"><div align="left"><span class="style2">Plumbing Related</span></div></td> </tr> <tr> <td> </td> <td><span class="style1"> <?php //Plumbing Related.php include (function_file.php); $sql="SELECT * FROM links WHERE category = 'Plumbing'"; function_name($sql);?> </span></td> </tr> <tr> <td colspan="2"><div align="left"><span class="style2">Plumbing Contractors </span></div></td> </tr> <tr> <td> </td> <td><span class="style1"> <?php //Plumbing Contractors.php include (function_file.php); $sql="SELECT * FROM links WHERE category = 'Plumbing Contractors'"; function_name($sql);?>[/PHPNET] |
|
#10
|
||||
|
||||
|
1. Looks like you need to add quotes:
Code:
include ('function_file.php');
2. You only need to include the file once, that the nifty thing about functions: it reduces double code. 3. Did you use <?php ?> tags in the include? You must, otherwise it will be handled as plain text and not parsed. 4. A lot more... Do you want to toy with it yourself or do you want us to rewrite it? |
|
#11
|
||||
|
||||
|
Quote:
PHP Code:
Don't forget in the function file to put at the very top <?php and at the very end ?> |
|
#12
|
|||
|
|||
|
OK, I have added the quotes and am still getting errors. I do have the <PHP tags in the include. The current errors I'm getting are: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/sites/site78/html/html/function_file.php on line 16 and Fatal error: Cannot redeclare function_name() (previously declared in /home/sites/site78/html/html/function_file.php:14) in /home/sites/site78/html/html/function_file.php on line 14 Thank you everyone for all your help on this. It is most appreciated. My skills are rusty |