homepage Welcome to WebmasterWorld Guest from 54.205.168.88
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Added new table
php, mysql, columns
IndulgenceDesign




msg:4488121
 9:37 pm on Aug 24, 2012 (gmt 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

 

cffrost2




msg:4488150
 11:38 pm on Aug 24, 2012 (gmt 0)

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

IndulgenceDesign




msg:4488374
 4:49 am on Aug 26, 2012 (gmt 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

cffrost2




msg:4488441
 2:36 pm on Aug 26, 2012 (gmt 0)

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.

IndulgenceDesign




msg:4488851
 9:56 pm on Aug 27, 2012 (gmt 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?

cffrost2




msg:4488896
 12:06 am on Aug 28, 2012 (gmt 0)

Hmmmm. What errors did you get?

cffrost2




msg:4488903
 12:16 am on Aug 28, 2012 (gmt 0)

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");
IndulgenceDesign




msg:4488991
 7:20 am on Aug 28, 2012 (gmt 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

cffrost2




msg:4489062
 12:53 pm on Aug 28, 2012 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved