Welcome to WebmasterWorld Guest from 54.198.221.13

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Added new table

php, mysql, columns

     
9:37 pm on Aug 24, 2012 (gmt 0)

New User

5+ Year Member

joined:Aug 24, 2012
posts: 7
votes: 0


Hi there,
First - this isn't my first time to this site, but I was previously signed up with a gmail account, so... here I am looking like a newb!

Okay, I've had to add a new column to the database table that controls our directory so that I can control how certain names appear within their departments.

I did not set this up originally, I took the site over 4 years after it's inception and have never had to change this until now.

I see nothing in the script that will let me control ordering by this new column, though it appears the directory is currently ordered by the auto-incremented id for each entry.

I believe the following is the code controlling what we're currently seeing:

<?php print $row['category']; ?></strong></td>
<td align="center"><?php print $row['main_line']; ?></td>
<td></td>
</tr>

<?php
$resultl = @mysql_query("select first_name, last_name, phone, email, category from directory, categories where department = categories.category_id and department= " . $row['category_id']);

while ($rowl = mysql_fetch_array($resultl)) {

?>
<tr>
<td width="340" valign="top" class="bodytext"><?php print $rowl['first_name']; ?> <?php print $rowl['last_name']; ?></td>
<td width="162" valign="top" class="bodytext" align="center"><?php print $rowl['phone']; ?></td>
<td width="162" valign="top" class="bodytext" align="center"><a href="#" onclick='<?php print despam($rowl['email']); ?>'><?php print $rowl['email']; ?></a></td>
</tr>
<?php
}
}
?>


can anyone please tell me how to add and order by the column "order"?
I'm good at what I do, but a lot of this was in place before I took over so I'm not what you'd call an expert at php - I'm trying to get there though!

Thanks in advance,
Sherry
11:38 pm on Aug 24, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:June 6, 2006
posts:103
votes: 2


Assuming the "order" column is part of this same table, decide if you want to list in ascending(asc) or descending(desc) order and simply add 'ORDER BY order ASC'
$resultl = @mysql_query("select first_name, last_name, phone, email, category from directory, categories where department = categories.category_id and department= " . $row['category_id']."ORDER BY order ASC); //or DESC sort


Hope this helps
4:49 am on Aug 26, 2012 (gmt 0)

New User

5+ Year Member

joined:Aug 24, 2012
posts: 7
votes: 0


I appreciate your response, I haven't had time to get to this until today so I apologize for getting to this so late.

I've tried moving the code around and use your suggestions but Dreamweaver keeps producing errors when I change it. I'm not really sure how it's happening; any ideas?

[i49.tinypic.com...] here is the error that DW is producing...

Thanks again, and in advance :)
Sherry
2:36 pm on Aug 26, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:June 6, 2006
posts:103
votes: 2


Hi. Looks like you're missing a " after ASC on line 619. I missed it too while quickly typing that code in I gave you 0_o. Oops.

It should look like this ".$row['category_id']." ORDER BY order ASC");

Hope that helps.
9:56 pm on Aug 27, 2012 (gmt 0)

New User

5+ Year Member

joined:Aug 24, 2012
posts: 7
votes: 0


I feel like a nuisance, but that still isn't working - when I put it in (took it out so I didn't get yelled at, lol) it gave header errors before populating some of the rest of the page, sorry, any ideas?
12:06 am on Aug 28, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:June 6, 2006
posts:103
votes: 2


Hmmmm. What errors did you get?
12:16 am on Aug 28, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:June 6, 2006
posts:103
votes: 2


Again. This should be working code now that I corrected the first error. Tell me what errors you see after this is implemented.
$resultl = @mysql_query("select first_name, last_name, phone, email, category from directory, categories where department = categories.category_id and department= " . $row['category_id'] . " ORDER BY order ASC"); 
7:20 am on Aug 28, 2012 (gmt 0)

New User

5+ Year Member

joined:Aug 24, 2012
posts: 7
votes: 0


Wish I'd seen your response sooner, I was away from the computer trying to pretend I have a life outside of this box ;)

The error that populates above the table that's supposed to be showing the listing is:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sbloom02/public_html/contact/directory_by_dept.php on line 621

no fewer than 20 times before it populates -- I'd give you the link but I have to keep taking the code out so none of the membership sees the errors. I guess I should have done this on a dev page but really didn't expect it to be this frustrating!

Thanks so much,
Sherry
12:53 pm on Aug 28, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:June 6, 2006
posts:103
votes: 2


Yes. I would save a test.php page and run the same script. But echo the $result1 var to see if it's valid. Add echo $result1 just below line 619 and see what it says. It should show the SELECT statement.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members