473,385 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP mySQL resource query?

384 256MB
I have this first piece of code which works fine but I'm trying to break it up into two parts like in the second code snippet below.
Expand|Select|Wrap|Line Numbers
  1. $tables = mysql_query("SHOW tables;");
  2. while($row = mysql_fetch_array($tables)) {
  3.     $tableNames .= "<a href=\"".$_SERVER['PHP_SELF'].">".$row[0]."</a><br/>\n";
  4.     $tableCount++;
  5. }
So it passes the sql query to the function and the function runs the query and should return the resource and store it in $tables variable and then the while loop should run through the $tables variable the same as in the first code snippet but it doesn't seem too work, its only outputting the first table name twice and there is over 100 tables!?
Expand|Select|Wrap|Line Numbers
  1. $tables = $this->dbQuery("SHOW tables;");
  2. while($tables) {
  3.     $tableNames .= "<a href=\"".$_SERVER['PHP_SELF'].">".$table."</a><br/>\n";
  4.     $tableCount++;
  5. }
  6. /******************************************/
  7. function dbQuery($queryIn) {
  8.     $resource;
  9.  
  10.     switch ($_SESSION['dbtype']) {
  11.         case 0:
  12.             $sql = mysql_query($queryIn);
  13.             $resource = mysql_fetch_array($sql);
  14.             break;
  15.     }
  16.  
  17.     return $resource;
  18. }
Aug 24 '11 #1
1 1813
Dormilich
8,658 Expert Mod 8TB
personally, I’d use foreach() like
Expand|Select|Wrap|Line Numbers
  1. // use CSS to make it a block element!
  2. $format = '<a href="'.$_SERVER['SCRIPT_NAME'].">%s</a>" . PHP_EOL;
  3. $tables = $this->dbQuery("SHOW tables;");
  4. foreach ($tables as $table) 
  5. {
  6.     $tableNames .= sprintf($format, $table);
  7. }
for which you need PDO (MySQLi as of PHP 5.4)

why your code (snippet) doeasn’t work is
- $table is undefined
- $tables doesn’t change
- $tableCount does not influence anything
Aug 24 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Benjamin Dickgießer | last post by:
Hi, I want to create a sql query but don't know if this is possible with mysql. The Query should do the following: Select all db entries from table in which entry a is smaller than the number...
13
by: aaron | last post by:
I have a question about (i think) joining. If I have a table in a database that has this info: key - name - favorite 1 - john - 2 2 - judy - 3 3 - joe - 1 the favorite icecream...
6
by: Xenophobe | last post by:
I know this isn't a MySQL forum, but my question is related to a PHP project. I have two tables. table1 table2 "table1" contains 2 columns, ID and FirstName:
3
by: Mike Cocker | last post by:
Hello, I'm quite weak at PHP, so I was hoping to get some help understanding the below code. First off, I'm trying to create a "query form" that will allow me to display the results on my...
1
by: Nick | last post by:
hi, all I convert some code from access to mysql. And I have a InboxMessage table which has From and To field. So, the query is like: select * from InboxMessage where To=12 12 is user id. This...
2
by: fusonts | last post by:
Can someon show me how to wirte a mySQL search query to search from only the open records. This is what I have but it continues to return records that are closed so I'm obviously doing something...
4
by: jpenney | last post by:
Hi, I gotta dum kweschin. Here's muh code: class dbServer{ ... public function &executeDBCOMMAND($SQL=";"){
3
by: xoinki | last post by:
hi all, I wanted to know few general details about MySQL slow query log. My slow log has a statement like # User@Host: root @ localhost here, what does this "" signify? why is this needed?...
2
by: dvelst | last post by:
Hi All, I have the following query which was based on a working query in MySQL: (don't be afraid of the size of the query you see below, later on I will concentrate on part of this query) ...
2
by: secutos | last post by:
I have the option of storing data online as text files, or storing data online in a MySQL database. If the information is stored as a text file, all I have to do is a HttpWebRequest to the text file...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.