CodeIgniter Forums
Nooby Codeigniter user! MYSQL Query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Nooby Codeigniter user! MYSQL Query (/showthread.php?tid=53041)



Nooby Codeigniter user! MYSQL Query - El Forum - 07-09-2012

[eluser]mr daniel[/eluser]
Hullo guys Smile


So I've just been playing around with codeigniter and mysql.
I need to execute the mysql query:
Code:
SELECT COUNT(id) FROM urls;
and want to show the result on the main page of my website.



So I've been trying something like
Code:
<php echo $idcount; ?&gt;
on the website and in my controller, "g.php" I've been using
Code:
$this->view_data['idcount'] = mysql_query(SELECT COUNT(id) FROM urls;);



Is there an easy way to do this?
I've been struggling so far Sad
Any help would be appreciated <3


EDIT: mistyped code


Nooby Codeigniter user! MYSQL Query - El Forum - 07-09-2012

[eluser]jmadsen[/eluser]
There sure is.

Here's the manual where they talk about how to use databases.

http://ellislab.com/codeigniter/user-guide/database/index.html


Nooby Codeigniter user! MYSQL Query - El Forum - 07-09-2012

[eluser]mr daniel[/eluser]
[quote author="jmadsen" date="1341823224"]There sure is.

Here's the manual where they talk about how to use databases.

http://ellislab.com/codeigniter/user-guide/database/index.html[/quote]

Thanks very much!

Trying it now but still struggling. Will keep going!


Nooby Codeigniter user! MYSQL Query - El Forum - 07-09-2012

[eluser]mr daniel[/eluser]
All fixed and done Big Grin

Was as simple as using
Code:
&lt;?php echo $this->db->count_all('urls'); ?&gt;