Hi all,
Im really baffled with this one. I have 2 tables that i simply wish to row count and display. the first works fine, but i just cant get the second to work, even if i rename the results variable
the code is below -
<?php
-
-
$link = mysql_connect("localhost", "un", "pw") or die('error 1<hr>'.mysql_error());
-
mysql_select_db("db", $link) or die('error 2<hr>'.mysql_error());
-
-
$result = mysql_query("SELECT ID FROM tbl_sellers", $link) or die('Query1 Error<hr>'.mysql_error());
-
$num_rows = mysql_num_rows($result);
-
-
echo "$num_rows Private Seller records\n";
-
echo "<br>\n";
-
-
-
$result = "";
-
-
$result2 = mysql_query("SELECT id FROM index-peaform", $link) or die('Query2 Error<hr>'.mysql_error());
-
$num_rows = mysql_num_rows($result2);
-
-
echo "$num_rows records\n";
-
echo "<br>\n";
-
mysql_free_result($result2);
-
-
mysql_close($link);
-
-
?>
-
-
7 2454
why don’t you use MySQL’s internal row counter? - SELECT COUNT(`id`) FROM table
I find aliasing the COUNT makes it easier to access. - $result = mysql_query('select count(*) as `count` from `table`');
-
echo mysql_fetch_object($result)->count;
* NOTE: PHP4 dislikes using the dereferencer (->) on non-variables, including directly on return values.
hi,
Thanks for the responses.
I dont think ive been clear. I understand the counts, but my problem is that the second query returns only an error. The table exists, and there is data to count, but all i get is the same error.
4 Private Seller records
Query2 Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index-peaform' at line 1
It's a good idea to always surround table and column names with "`" characters. Also, it is standard to use underscores instead of dashes for this exact reason. SQL sees dashes as the subtraction operation, not as a character in a name.
Ding, ding, ding... And the prize goes to kovik!
Hi,
Thank you all for your responses but my question is regarding the code in that the first query runs, the second one doesnt.
I dont see how your responses relate to my question
Really, ~whitep8? Did you even read my response...?
Basically, replace this: - SELECT id FROM index-peaform
With this: - SELECT `id` FROM `index-peaform`
And like I said, for future reference, DO NOT USE DASHES in table names or column names. Use underscores.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: RG |
last post by:
Hopefully someone here can help.
I would like to perform multiple queries to a MySQL database and have all
the results in 1 result set.
Is this possible?
TIA
RG
|
by: Craig Keightley |
last post by:
I need to create a form using multiple quantities that can be updated by one
single update.
eg:
(HTML PAGE)
<form method="post" enctype = "multipart/formdata">
<? do { ?>
<?php echo...
|
by: Ralph Guzman |
last post by:
TASK:
I have to generate a report with all categories, subcategories and
products in database.
PROBLEM:
I want to write one query that will return:
1. category
2. subcategory: determined by...
|
by: Rob |
last post by:
Good afternoon,
I'm looking for information on good benchmarking implementations
with which to test MySQL using multiple clients. The benchmark
utilities included with MySQL are, as far as I...
|
by: Mark Everett |
last post by:
Hi,
I am currently running out of space on one of my database servers. Is
it possible to move the relevant files for tables onto another drive
and instuct MySql to use both folders for it's...
|
by: DG |
last post by:
Hi,
Can anyone advise how to execute multiple statements in a single query
batch. For example-
update customers set customer_name = 'Smith' where customer_name =
'Smyth';
select * from...
|
by: CountDraculla |
last post by:
Fixing Multiple Database bug in adoDB
popular data access layer for php, adoDB can support multiple databases
from different provider at time, but not from same provider. what I
mean is if you...
|
by: Daz |
last post by:
Hi. I am trying to select data from two separate MySQL tables, where I
cannot use join, but when I put the two select queries into a single
query, I get an error telling me to check my syntax. Both...
|
by: paladin.rithe |
last post by:
I have 2 statements that I'd like to string together in a query, but
according to everything I'm seeing, it's not possible.
What I'm doing is an insert of a row, where the primary key is an auto...
|
by: kumarboston |
last post by:
Hi All,
I have a mysql database and 3 pages which queries and returns the data.
1st page(main.html) is just a form in html which takes query from the user and is connected to "form...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |