Jump to content

display total links from database


Jack.C

Recommended Posts

Hello all, Happy Holidays!

 

I have a question here, and I'm sure it has been answered before, but I couldn't find it via the search. So sorry if it has been answered before.

 

What I have is a script that displays full episodes of tv shows, where each episode is a category added to a tv show, or in this case a "movie".

 

What I would like to accomplish is show the total number of episodes (every category on the site.) and the total number of tv shows (every movie added.)

 

To display something like this:

 

 

Total TV Shows: 1,000 (where the total comes from the amount of Movies added to the database.)

 

Total Episodes: 1,000 (where the total comes from the amount of categories added to the database.)

 

And also if possible. a way to show the last five items added in the category table.

 

Thanks,

Jack

Link to comment
Share on other sites

Hello all, Happy Holidays!

Hi Happy Holidays

 

I'll assume this in a SQL Database, and you have the following fields

ID = an autonumber (likely primary)

Added = timestamp for when the reocrds was created (recommeded)

Name = Movie Name

Categories = Movie categories  (i'll also assume you have data with this field containing TV an Episodes

and i'll guess the table is called Movies

 

Total TV Shows: 1,000 (where the total comes from the amount of Movies added to the database.)

SELECT count(*) as TotalMovies  FROM Movies

$Row['TotalMovies']

 

Total Episodes: 1,000 (where the total comes from the amount of categories added to the database.)

SELECT count(*) as TotalCats FROM Movies GROUP BY Categories

$Row['TotalCats']

 

And also if possible. a way to show the last five items added in the category table.

SELECT * FROM Movies ORDER BY Added DESC Limit 5

you could used ID instead of Added but i recommend you have a timestamp

 

Hope that helps

 

i assumed alot so it probably wrong lol

Link to comment
Share on other sites

PHP doesn't understand SQL. You can just dump SQL code into a PHP script and expect it to work. You'll first need to connect to mysql server using mysql_connect, followed by mysql_select_db to use a MySQL database.

 

To run your queries you'll use mysql_query. In order to retireve results from your query you'll use mysql_fetch_assoc.

 

Altogether

<?php

mysql_connect('localhost', 'your_mysql_username', 'your_mysql_password') or die(mysql_error());
mysql_select_db('your_mysql_database') or die(mysql_error());
// your query
$sql = 'SELECT count(*) as TotalMovies  FROM movies';
$result = mysql_query($sql or die(mysql_error());

// get the total number of movies
$row = mysql_fetch_assoc($result);
echo $row['count(*)'];

?>

Link to comment
Share on other sites

Thanks.

 

One last question, how do I style the results? Like in a table or something.

 

Right now the results show as just numbers 5,24. How can I make it like

 

Total TV Shows : 5.

Total Episodes: 24

 

With some style around them? Like in a table or something.

Link to comment
Share on other sites

Post your full code here.

 

The code right now is just those queries you posted above. I want to style them before I put them somewhere. But anytime I try to add text before the echo $row['TotalMovies']; I get an error. So where do I begin styling, and adding text etc?

Link to comment
Share on other sites

To output text/HTML/JS/CSS etc you'll need to put it within an echo statement. Example

 

<?php

mysql_connect('localhost', 'your_mysql_username', 'your_mysql_password') or die(mysql_error());
mysql_select_db('your_mysql_database') or die(mysql_error());
// your query
$sql = 'SELECT count(*) as TotalMovies  FROM movies';
$result = mysql_query($sql or die(mysql_error());

// start HTML table
echo '<table border="1" cellpadding="5" cellspacing="0">
  <tr>
    <th>Total Movies</th>
';

// get the total number of movies
$row = mysql_fetch_assoc($result);

// display TotalMovies within a table cell
echo '    <td>'.$row['TotalMovies'].'</td>';

// end HTML table
echo '  </tr>
</table>';

?>

Link to comment
Share on other sites

By display do you mean have PHP code visible on the page? Or have PHP code run within a .tpl

 

For the latter you can just use include to parse PHP code within a .tpl eg

 

include 'file_with_php_code.tpl';

 

To display actual PHP code you'll need to convert it to HTML special chars, eg

$php = '<?php echo "hello world"; ?>';

echo htmlentities($php, ENT_QUOTES);

Link to comment
Share on other sites

What I have is a script that was built in/around .tpl files. http://watch.thetvstop.com/

 

I want to display the results of total links, and total episodes in the right sidebar of the above page, within <div> tags like the rest of the sidebar.

 

So would I just create a .tpl file with the php code to display the results from the db, and with the style of the box for the right sidebar?

 

I have tried many times to insert php into a .tpl and had no success. =/ So I assume creating a .tpl with just php would work?

Link to comment
Share on other sites

it depends on how your calling the .tpl file.. if you include it it should work fine..

if your getting its contents then you could use str_replace() to replace a marker/tag

 

ie

Hello world We have <!--MovieCount--> Movies

 

$movies = 100;
$str = file_get_contents("myfile.tpl");
$str = str_replace("<!--MovieCount-->", $movies, $str);

echo $str;

 

Hello world We have 100 Movies

 

 

If your using ITX then you could try this

add {Movies} to the tpl flie

 

look in your code for something like this

$template = new HTML_Template_ITX

its the part that loads in your template..

Note the Red part and use the same below

Now add this after the SQL query

$MoveCount = 999;

$template->setVariable("Movies", $MoveCount);

Link to comment
Share on other sites

The .tpl files are in a templates directory. Where movies_list.tpl serves as the index. As I have not written this script myself, somebody else did, I have no clue as to how the tpl files are being called. I just know how to edit them, and what they edit. I have never worked with tpl files before.

 

I have searched all the files that are not in the admin directory, template files and php files and did not find "$template = new HTML_Template_ITX" anywhere. So I would assume they are not being included?

 

The template files structure are like:

 

movies.tpl (this is the template that styles/displays) the content of a single movie.

movies_list.tpl (this file serves as the index page.)

links.tpl (this file serves as the way to style each link once "view link" is clicked.

overall.tpl (I would assume this is the main file, as it has the html doctype etc.)

 

 

 

 

Link to comment
Share on other sites

By display do you mean have PHP code visible on the page? Or have PHP code run within a .tpl

 

For the latter you can just use include to parse PHP code within a .tpl eg

 

include 'file_with_php_code.tpl';

 

The include doesn't work. see the rightsidebar "stats" here: http://watch.thetvstop.com/

 

If you go directly to the .tpl file however it works. http://watch.thetvstop.com/templates/stats.tpl

 

The problem lies within including, how do I fix that?

Link to comment
Share on other sites

When using PHP code ensure you place it within PHP tags (<?php ?>)

 

Also when using include you'll need to use the absolute/relative path to the file you're including, not just state the filename. In your case the path will be templates/stats.tpl

 

<?php include 'templates/stats.tpl'; ?>

Link to comment
Share on other sites

When using PHP code ensure you place it within PHP tags (<?php ?>)

 

Also when using include you'll need to use the absolute/relative path to the file you're including, not just state the filename. In your case the path will be templates/stats.tpl

 

<?php include 'templates/stats.tpl'; ?>

 

I have done this, and it doesn't display anything from the stats file where it is included. It's supposed to show on http://watch.thetvstop.com in the right sidebar, under "stats" and as you can see it's blank.

 

<?php include 'templates/stats.tpl'; ?>

 

Is the code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.