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
https://forums.phpfreaks.com/topic/42931-need-help-please/#findComment-208531
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
https://forums.phpfreaks.com/topic/42931-need-help-please/#findComment-208532
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
https://forums.phpfreaks.com/topic/42931-need-help-please/#findComment-208533
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
https://forums.phpfreaks.com/topic/42931-need-help-please/#findComment-208541
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
https://forums.phpfreaks.com/topic/42931-need-help-please/#findComment-208885
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
https://forums.phpfreaks.com/topic/42931-need-help-please/#findComment-208931
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
https://forums.phpfreaks.com/topic/42931-need-help-please/#findComment-208985
Share on other sites

you would have to set an id variable based on that page...

 

usually this is done with http://domain.com?page=123

 

you would then use the $_GET['page'] global array to grab the variable page.

 

then you would use that to get the rest of the page from your DB.

Link to comment
https://forums.phpfreaks.com/topic/42931-need-help-please/#findComment-209074
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
https://forums.phpfreaks.com/topic/42931-need-help-please/#findComment-209077
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.