Jump to content

Need Help please


tcorbeil

Recommended Posts

Ok..  I confess that I'm a newbie with respect to PHP..

 

I your code, let's say I open up the webpage google.ca..  The page title is google... in the code you presented, would the variable $title = google?  If this is the case, then yes this is what I'm after..

 

Thanks.

Link to comment
Share on other sites

if you want to get what some other page is displaying that will not work...

 

if you are writing a page, and you want google to be your title... the you would assign the string google to the variable $title and echo (or print) that in between your title tags.

Link to comment
Share on other sites

Ok..  I confess that I'm a newbie with respect to PHP..

 

I your code, let's say I open up the webpage google.ca..  The page title is google... in the code you presented, would the variable $title = google?  If this is the case, then yes this is what I'm after..

 

Thanks.

no, understand this, PHP is not like html it is known for doin the background work. HTML is still used to edit <title> and make tables etc.

 

Link to comment
Share on other sites

Thanks for your replies. Actually I do get the PHP doing the work concept.. I have many pages for my own website and a database storage for each page..  I was hoping to use the page title to store into a php variable so then I could retrieve the information required from the appropriate database (given name by the page title..)  There might be another way of doing this but so I welcome any other suggestions to the matter.

 

Basically something like this in english:

 

The setup:

Database has several table aaaa, bbbb, cccc.

 

1) PHP script: get page title and store in a variable called $pageID (page title is cccc) therefore $pageID = cccc

2) php script to get all information in mySQL under cccc and return to print on website

 

Note: Because all pages are going to be generic and reading into an external php script, I don't want to assign a specific variable to a page (too many pages to edit) I want to be able to get the page ID and run with that..

 

Is this doable or is there a better way?

 

Thanks

T.

Link to comment
Share on other sites

open database and connect...

 

then, query getting the data you want... ie,

 

SELECT * FROM main WHERE page_title='$page_title'

 

then based off of that, you can set your variables for title, content, etc... and echo those out to the page.

Link to comment
Share on other sites

sorry.. hit the wrong button and submitted too soon.. here is the full message..:

 

Ok so let's say I have this:

 

my SQL table called 'main'.

 

In main I have colums such as:

 

index        page name        content 1        content 2

-----------------------------------------------------

1            aaaa                blahblah          blahblah

2            bbbb                blahblah          blahblah

3            cccc                blahblah          blahblah

4            aaaa                blahblah          blahblah

5            cccc                blahblah          blahblah

6            aaaa                blahblah          blahblah

 

Ok, so I want to retrieve the page name such as for example, 'aaaa' and use the select command to query mySQL and pull all the information on the rows listed aaaa.. 

 

I tried your suggestion but i may need more info to implement the code.. 

 

right now I have:

$query="SELECT * FROM `Entertainment` WHERE 1"; and it works.. only thing is, I need a table for every page..

 

Thanks again for the help.

T.

Link to comment
Share on other sites

<?php
$index_id=$_GET['id']; //however your retrieving the data... be it GET or POST 

//connect to your DB... then query it with the $index_id variable
$query="SELECT * FROM main WHERE index='$index_id'";
$result=mysql_query($query);

//assign the content of the DB to variables
$page_name=mysql_result($result,0,'page_name');
$content_1=mysql_result($result,0,'content_1');
$content_2=mysql_result($result,0,'content_2');

//print the variables and any html formatting you want to the screen.
echo "<title>$page_name</title>";
echo "More code etc....";
echo "more stuff... ";
?>

Link to comment
Share on other sites

Here is a piece of code interpim:

 

$query="SELECT * FROM `Entertainment` WHERE Page ='$index_id'";

$result=mysql_query($query);

 

This works good if i declare the variable prior:

 

$index_id = "xbox.php" (where xbox.php = to the name of the current page I'm viewing in a browser and is also a value in mySQL under 'page' column in a table called Entertainment)

 

I tried doing $index_id = $_GET['ID'] as you mentioned but it didn't work..

 

Aside from me declaring the the $index_id variable should be equal to the page name I am on, how do I make $index_id variable get the page name automatically?  (ex. if I'm in IE and I'm viewing a site called www.xxxx.com/xbox.php, i would want $index_id to be assigned the value xbox.php)

 

I'm still stuck..

 

Thanks for your patience.

 

T.

Link to comment
Share on other sites

Alright, what you want to do is webfetching basically. You want to read in the contents of an external website and put the title into a string. Here is one way to do it:

 

<?php
$file = file_get_contents('http://www.google.com/');

list(,$title) = spliti('</title>', $file);
list($title) = spliti('<title>', $file);

print $title;  //should print "Google"
?>

 

 

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.