![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| I have a web page in which I want to display the count of records in a particular table. For example: <?php @ $db = mysql_connect('localhost','username','password'); if (!$db) { exit; } mysql_select_db('wp21'); $qryblog21_posts = "select count(*) -1 as ct from wp01_posts"; $qryblog21_comments = "select count(*) -1 as ct from wp01_comments"; $result21_posts = mysql_query($qryblog21_posts); $result21_comments = mysql_query($qryblog21_comments); $array21_posts = mysql_fetch_array($result21_posts); $array21_comments = mysql_fetch_array($result21_comments); mysql_close; if ($array21_posts && $array21_comments) { echo $array21_posts[0]; echo "</br>"; echo $array21_comments[0]; } ?> This seems to work, and I think I can figure out how to get those two variables into a table for the purpose of displaying them. But is this the right way to go about this? Or am I missing something? Thanks in advance. | |||
| | #2 | ||
| deko wrote: > I have a web page in which I want to display the count of records in a > particular table. > > For example: > > <?php > @ $db = mysql_connect('localhost','username','password'); > if (!$db) > { > exit; Do you really want to stop your script here? I would ask myself: Is it crucial to have the numbers for posts and comments? If yes, then exit. If the numbers are not crucial, then set them to '0' and go on with your script. > } > mysql_select_db('wp21'); > > $qryblog21_posts = "select count(*) -1 as ct from wp01_posts"; > $qryblog21_comments = "select count(*) -1 as ct from wp01_comments"; > > $result21_posts = mysql_query($qryblog21_posts); > $result21_comments = mysql_query($qryblog21_comments); > > $array21_posts = mysql_fetch_array($result21_posts); > $array21_comments = mysql_fetch_array($result21_comments); > > mysql_close; > > if ($array21_posts && $array21_comments) > { > echo $array21_posts[0]; > echo "</br>"; > echo $array21_comments[0]; > } > ?> > > This seems to work, and I think I can figure out how to get those two > variables into a table for the purpose of displaying them. But is this > the right way to go about this? Or am I missing something? The rest of your script looks ok. Bye, Hakan -- Hakan Kuecuekyilmaz | |||
| Featured Websites | ||||
|
![]() |
| Tags: counts, display, newbie |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| display errors | Rob | PHP | 1 | 07-01-2007 3:55 PM |
| forum display | David & Angela Ehmer | PHP | 0 | 07-01-2007 3:36 PM |
| How to Display 16-bit grayscale | benn686@hotmail.com | Software Programming | 0 | 06-12-2007 11:53 PM |
| Greyscale display | Colin Cook | Operating Systems And Software | 0 | 05-29-2007 12:54 AM |
| WDS Display Problem... | NewMan | MSN questions | 1 | 05-28-2007 1:44 AM |
| Featured Websites | ||||
|