Database Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesDatabase Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Laplink Gold 2008 - $15 Off with Coupon Code CJM9NE
  #1  
Old May 27th, 2003, 01:17 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Question on Database connect...

Quick question... am I connecting to the database twice in this line of script? I don't think I need to..only once. How can this be written better?

I am connecting to two different tables in same database...
the include file contains database, user, pass. info.

PHP Code:
<?php
include "config.php";
      
$query "SELECT * FROM othertablename ORDER BY title";
      
$result = @mysql_query($query$connection) or die(mysql_error());
      while (
$row mysql_fetch_assoc($result)) {
      
$title stripslashes($row['title']);
      
$name stripslashes($row['name']);
      
$foldernamelinks "webpages";
      
$display1 .="
      <li> 
      <a href= $foldernamelinks/$title>$name</a><br>
      </li>
      "
;}
      
?>
        <?php echo "$display1"?> </ul></td>
    <td colspan="6" rowspan="2" valign="top">
<p>Quick Events / by recent post:</p>
      <p> 
        <?php
      $query 
"SELECT * FROM table ORDER BY title";
 
$result = @mysql_query($query$connection) or die(mysql_error());     
while (
$row mysql_fetch_assoc($result)) {
    
$title stripslashes($row['title']);
    
$date = ($row['date']);
    
$body stripslashes($row['body']); 
    
$display .="
    <li>
    <p><strong>$title</strong> <br>
    <STRONG>$date</STRONG> <br>
    <strong>$body</strong>
    </li><br><hr>
"
;}




* Also, is it good practice to close the database connect?
__________________
bow wow!

Reply With Quote
  #2  
Old May 27th, 2003, 02:13 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
well from the piece of code you posted, you are making 1 database connection, identified by $connection. You are making 2 database queries.

Quote:
How can this be written better?


what I like to do is move static variables into 1 file or into an array.
PHP Code:
 $foldernamelinks "webpages"

I would put code like this in a config file rather then in the actual code.

another thing I might do is get rid of $display1 and make a function out of it. maybe call it, display_link()

PHP Code:
function display_link($foldernamelinks$title$name)
{
     echo(
"
      <li> 
      <a href='$foldernamelinks/$title'>$name</a><br>
      </li>"
);



then call it in the code where you need it

PHP Code:
<?php  display_link($foldername$title$name); ?> </ul></td>


As long as it works, it is up to you
__________________
-- Jason

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesDatabase Development > Question on Database connect...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway