Page 3 of 5

Posted: Mon Aug 14, 2006 9:23 pm
by RobertGonzalez
For testing, change this:

Code: Select all

$result = mysql_query("SELECT * FROM settings") or die('There was an error in the query at line ' . __LINE__ . ' of the script: ' . mysql_error());
while ($row = mysql_fetch_array($result)) {
    $settings[$row['name']] = $row['value'];
}
To this:

Code: Select all

$result = mysql_query("SELECT * FROM settings") or die('There was an error in the query at line ' . __LINE__ . ' of the script: ' . mysql_error());
while ($row = mysql_fetch_array($result)) {
    echo '<p>We are about to make an array var named $settings[<strong>' . $row['name'] . '</strong>] that has a value of ' . $row['value'] . '.</p>';
    $settings[$row['name']] = $row['value'];
}
Also, make sure that the query that makes the $settings array is called before you use any of the $settings elements, or they will all be blank (and throw undefined index notices at you).

Posted: Mon Aug 14, 2006 9:26 pm
by adamb10
Your code returns...
We are about to make an array var named $settings[] that has a value of .

From is 0 and max_results is ...

And the query is: SELECT * FROM comments ORDER BY Date DESC LIMIT 0,
There was an error in the query at line 62 of the script: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
[/quote]

Posted: Mon Aug 14, 2006 9:32 pm
by adamb10
Let me tell you how this all started...

I used a custom mysql function and because of the function the script was inefficent. The same query was used up to 4 times in the file. Thanks to help from some friends I optimized the code into its current form.

Posted: Mon Aug 14, 2006 9:34 pm
by RobertGonzalez
You are not getting from your settings table what you expect. It appears that there is not data in settings, or the field names are not properly referenced. What are the field names of the settings table (with exact case and spelling)?

Posted: Mon Aug 14, 2006 9:36 pm
by adamb10
title
tablewidth
menubar
posting
kwikpost
kwikpostlocation
maxshow
im
links
logo
menubarlocation
bbcode
avatars

Posted: Mon Aug 14, 2006 10:19 pm
by RobertGonzalez
That is your problem... you are trying to reference a nonexistent field. There are no fields named 'name' or 'value' in your table.

Posted: Mon Aug 14, 2006 10:23 pm
by adamb10
hmmm...is there a way to grab everything without specifiying it all?

Posted: Mon Aug 14, 2006 10:26 pm
by RobertGonzalez
Thinking about it, your settings table should have two fields: setting_name and setting_value. Then, for each row in the table, assign one of your settings as the setting_name and give it a value so your table output would look like this...

Code: Select all

+------------------+-------------------+
|   setting_name   |   setting_value   |
+------------------+-------------------+
| title            |                   |
+------------------+-------------------+
| tablewidth       |                   |
+------------------+-------------------+
| menubar          |                   |
+------------------+-------------------+
| posting          |                   |
+------------------+-------------------+
| kwikpost         |                   |
+------------------+-------------------+
| kwikpostlocation |                   |
+------------------+-------------------+
| maxshow          |                   |
+------------------+-------------------+
| im               |                   |
+------------------+-------------------+
| links            |                   |
+------------------+-------------------+
| logo             |                   |
+------------------+-------------------+
| menubarlocation  |                   |
+------------------+-------------------+
| bbcode           |                   |
+------------------+-------------------+
| avatars          |                   |
+------------------+-------------------+
Then, when you select from the table you would do this to make your settings...

Code: Select all

<?php
$result = mysql_query("SELECT * FROM settings") or die('There was an error in the query at line ' . __LINE__ . ' of the script : ' . mysql_error());
while ($row = mysql_fetch_array($result)) {
// REMOVE THIS LINE WHEN TESTING IS DONE!!!!
    echo '<p>We are about to make an array var named $settings[<strong>' . $row['setting_name'] . '</strong>] that has a value of ' . $row['setting_value'] . '.</p>';
    $settings[$row['setting_name']] = $row['setting_value'];
}
?>

Posted: Mon Aug 14, 2006 10:40 pm
by adamb10
Wait, thats how it is now. I got field and table confused. I didnt make any fields though.

I dunno, I'm confused at this point.

Posted: Mon Aug 14, 2006 11:21 pm
by RobertGonzalez
Do a mysql dump of your settings table and data and post that information here. That is about the only way to see what is really happening in your table. But at this point, your settings setter will always return an empty set of settings because your are using field names that, as far as I know from what you are telling me, do not exist in the table.

Posted: Tue Aug 15, 2006 4:03 am
by MarK (CZ)
MarK (CZ) wrote:My guess is you're using bad values here:

Code: Select all

$q = 'SELECT * FROM comments ORDER BY Date DESC LIMIT '.$from.', '.$max_results.'';
I was right from the beginning :P

However this thread got a bit unreadable, do you ppl have to reply so fast??? :lol:

Posted: Tue Aug 15, 2006 4:21 am
by RobertGonzalez
Yep, you were right. Specifically it was the $max_results var that was causing the fits because of the way it was set (or not set, as it were).

Posted: Tue Aug 15, 2006 10:13 am
by adamb10

Posted: Tue Aug 15, 2006 10:54 am
by MarK (CZ)

Code: Select all

//Query Settings Table
$result = mysql_query("SELECT * FROM settings");
while ($row = mysql_fetch_array($result)) {
    $settings[$row['name']] = $row['value'];
}

//Query Colors table
$result = mysql_query("SELECT * FROM colors");
while ($row = mysql_fetch_array($result)) {
    $colors[$row['name']] = $row['value'];
}
    

$result = mysql_query("SELECT * FROM images");
while ($row = mysql_fetch_array($result)) {
     $images[$row['name']] = $row['value'];
}

$max_results = $row['maxshow'];
$from = ($page * $max_results);
But hey, you're trying to get $row['maxshow'] from images table, not from settings table. Move the assignment of $max_results right after the query to settings table (before doing any other query).

Posted: Tue Aug 15, 2006 11:31 am
by adamb10
maxshow is in the settings table.