corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Php help? (mysql_num_rows) » Post Reply

Post Reply
Who Can Post? All users can post new topics and all users can reply.
Icon:
Formatting Mode:
Normal
Advanced
Help

Insert Bold text Insert Italicized text Insert Underlined text Insert Centered text Insert a Hyperlink Insert Email Hyperlink Insert an Image Insert Code Formatted text Insert Quoted text
Message:
HTML is Off
Smilies are On
BB Code is On
[img] Code is On
Post Options: Disable smileys?
Turn BBCode off?
Receive email notification of new replies?

Dom

posted on 15th Jan 10 at 14:38

php.net, for explainations and examples ;) :thumbs:

A good understanding of functions and classes, and the differences is also worth the reading, especially when and when not to use either....


Sam

posted on 15th Jan 10 at 13:48

:)


ed

posted on 15th Jan 10 at 13:17

Alright alright, he seems a clever lad I'm sure he'll see the suggestions and be able to do a bit of reading around.


Sam

posted on 15th Jan 10 at 12:37

Yes I know it's not hard, but he needs to learn what the functions do first. It's all very well telling him to do this that and the other but if he doesn't understand what the hell things do he won't understand how/why he needs to do them different as he progresses!


ed

posted on 15th Jan 10 at 12:27

Learning how to write things into modular functions the first time round isn't exactly hard though. It promotes you to properly plan a structure also which saves a lot of time.


Sam

posted on 15th Jan 10 at 12:18

I think Whittie needs to first understand how he has to do things, before learning how to do them differently?


Whittie

posted on 15th Jan 10 at 12:10

Got a lot to learn :(


ed

posted on 15th Jan 10 at 12:05

I also tend to write a function for mysql queries. So that:

$sql="SQL QUERY";
$query=mysql_query($sql);

becomes:

$query=dbQuery("SQL QUERY);

Which you can re-use all over the site.

[Edited on 15-01-2010 by ed]


ed

posted on 15th Jan 10 at 12:04

Also, store your MySQL connection in a file and include it in every page you require a connection. Modularity again...


ed

posted on 15th Jan 10 at 12:02

For what you want you should either write it so that it echos the data as JSON, or you should write it as a function which returns the value. It makes your script more modular and you can re-use it else where in the site. If you have it return it as JSON then you would then need some Javascript to get it onto the page, but then with a bit of AJAX you could have it update live. No real need to do it what way, but it's just the difference between a website an a web app :)


Sam

posted on 15th Jan 10 at 10:42

:D :wave:

That Tizag site I find very useful/helpful, as well as the W3Schools website.


Whittie

posted on 15th Jan 10 at 10:26

Perfect! Thanks Sam :wave:


Sam

posted on 15th Jan 10 at 10:22

http://www.tizag.com/mysqlTutorial/mysqlcount.php


Whittie

posted on 15th Jan 10 at 10:05

Been looking online and in my book. They both say this should work, but it doesn't :o (Obviously, yes i did replace the user / password / db name).

code:


<?php

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?>





Whittie

posted on 15th Jan 10 at 09:41

Thank you :)


Laney

posted on 15th Jan 10 at 09:30

quote:
Originally posted by ed
In PHP MySQL you'd use MYSQL_NUM_ROWS to retrieve the number of records in a table.


Or possibly a SELECT COUNT(*) on the table :)


ed

posted on 15th Jan 10 at 07:46

In PHP MySQL you'd use MYSQL_NUM_ROWS to retrieve the number of records in a table.


Whittie

posted on 15th Jan 10 at 01:25

http://is.gd/

Where it says underneath how many current urls have been shortened, how would I do this??

Need something to count how many urls are currently in the db and display it, but how could I do it?

Any help is appreciated, thanks!

[Edited on 15-01-2010 by Whittie]