View Full Version : Quick MySQL Question...
LMS16
21-02-2010, 12:50 PM
Ok so it sounds nooby but...
How would I fetch the number of rows from a database, if I wanted to see how many rows include the word "admin" within its tables.?
Its hard to explain lol but I wanna see how many tables have the word "admin" in them? Can someone help me with the mysql query please?
I thought it would be some like
mysql_num_rows(mysql_query("SELECT '$username' FROM `table`"));
But obvs not... HELP? lol,
Thanks lol :)
Lew.
Johno
21-02-2010, 01:30 PM
It would probably be something like:
$query = mysql_query("SELECT * FROM `table` WHERE `whatever the row is` = `Admin`");
$query = mysql_num_rows("$query");Not entirely sure but, hope that helps :)
LMS16
21-02-2010, 01:40 PM
No I mean Ive got a table and it has different tables inside that such as "tta, ttb, ttc ect..." and I want to find how many of those tables have the users username in it so for example, "tta='admin', ttb='admin'" so the number of rows would be 2...
Lew.
Could try
<?php
$query = mysql_query("SELECT * FROM `table`");
$count = 0;
while( ( $fetch = mysql_fetch_assoc( $query ) !== false )
{
foreach( $fetch as $key => $value )
{
( $value == "admin" ) ? $count++: false;
}
}
echo $count;
?>
Try that.
Johno
21-02-2010, 02:10 PM
This might help if you are trying to select the same named column from multiple tables, http://stackoverflow.com/questions/409705/mysql-selecting-data-from-multiple-tables-all-with-same-structure-but-different :)
LMS16
21-02-2010, 03:23 PM
Hmmm,, basically I'm making a timetable script and I want to be able to tell the user how many shows they have booked that week...
Anyone care to explain in a little more details cos me minds gone blank and I cant think of a way... S:S:S:S
Lew.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.