Jump to content

Query by page title?


amg182

Recommended Posts

Hi guys.

 

Is it possible to use a WHERE clause that uses the page name or file name?

I presume its a tag of some sort...?

 

For example

Select * FROM db_name WHERE Field_name='Page_title'

 

I want to query my results using the page name or title, this would say me creating multiple queries.

 

Any help would be appreciated.

 

Thanks

Link to comment
Share on other sites

The page name is within my page <title></title> tags only-not a variable.

 

Lets say I have a web page called John.php and I want to query all the people show names are John.

 

I would use

$sql = "SELECT COUNT(*) FROM (SELECT * FROM `People` WHERE Name='john') subq";

 

Which works just fine.

 

But I would like to have the WHERE clause to change dynamically as the page name changes.

Is this possible?

 

Thanks again

Link to comment
Share on other sites

Ah, I see. The easiest way would be just define a page_title variable and stick it in both the <title></title> and the query.

 

The hardest way would be to use file_get_contents and scrape the HTML till you get the <title></title> text.

Link to comment
Share on other sites

Hi,

 

I'm so sorry but I have very limited experience with php....  and have no idea how to create a variable...:shy:

 

How would i implement this to my code?

 

 


<Title>John</title>

<?php

//connect to db

$result = mysql_query("SELECT * FROM `students` WHERE Name='pagetitle');

<table>
<tr>

while($row = mysql_fetch_array($result))
  {
  
<td>' . $row['Name'] . '</td>
<td> . $row['Surname] . '</td>
<td>' . $row['Age'] . '</td>
<td>' . $row[ASP'] . '</td>
    
  </tr>
  }
</table>

mysql_close($con);
?> 

 

Thanks once again.

 

Link to comment
Share on other sites

Here's a starting spot.

 

 

<?php define("CONSTANT", "John."); ?>

<Title><?php echo CONSTANT; ?></title>

<?php

//connect to db

$result = mysql_query("SELECT * FROM `students` WHERE Name='CONSTANT');

echo '<table><tr>';

while($row = mysql_fetch_array($result)) {
  
echo '<td>' . $row['Name'] . '</td>';
echo '<td>' . $row['Surname] . '</td>';
echo '<td>' . $row['Age'] . '</td>';
echo '<td>' . $row['ASP'] . '</td>';
  
}
echo '</tr></table>';

mysql_close($con);
?> 

Link to comment
Share on other sites

I rushed though that use this instead.

 

<?php define("CONSTANT", "John."); ?>

<Title><?php echo CONSTANT; ?></title>

<?php

//connect to db

$result = mysql_query("SELECT * FROM `students` WHERE Name=CONSTANT");

echo "<table><tr>";

while ($row = mysql_fetch_array($result)) {
  
echo "<td>'" . $row['Name'] . "'</td>";
echo "<td>'" . $row['Surname'] . "'</td>";
echo "<td>'" . $row['Age'] . "'</td>";
echo "<td>'" . $row['ASP'] . "'</td>";
  
}

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

mysql_close($con);
?> 

Link to comment
Share on other sites

Hi Coolascarlito.

 

Thanks for reply, just had a go at the variable, and works perfectly. Yeah, I have purchased some O'Reilly books to learn more about PHP- hopefully get them this week!

I have literally just started using php... Its quite daunting.

 

Thanks again!

Link to comment
Share on other sites

Your welcome and I said all of that because when I first started out I just went in with it and didn't really know the basics of php or some stuff of programming in general and just tried messing with trial and error which is how a lot of noobs operate. And I've gained a some good friends off this web site that when I get in a crunch they are always there to explain to me a syntax issue or what not but books are there for a reason. But like I said glad to help you.

Link to comment
Share on other sites

You want the core basics in a semi direct manor.. i picked up this site many years ago.. tizag.com they are basically a core basics sites. Which will give you the stepping stones to learn quickly. And they do it with visible examples. Over all not a bad site, they also have various references there from static HTML to mySQL, PHP, JavaScript.. etc.. I would say before continuing on you at the least study that site and its references. I mean this with no disrespect. But I also say it with a firm guiding tone :-)

 

Trust me, knowing at the least the basics before you come on to a forum like this will save you a lot of frustration. As some people can be brutal savages more so cause they don't remember the years they struggled through. Also being as descript as you can without dropping 200+ lines of code with only "This is broken how do I fix it" as the description (*cough* carlito... *cough, cough*) is helpful too.

 

One thing I also want to mention is the books you ordered, and sites you are going to come up with in general til you start getting more familiar with the code your intent on using aren't likely to mention the concept of code injection tizag I know covers it lightly but. If your developing a site where a user can change any variable through the browser its worth reading up on "XSS Attacks" and "Injection Prevention" it will save you a lot of headache in the future to implement good security now

Link to comment
Share on other sites

On  a side note I would here and there just look around for other active threads and try and pick up on a some other things that others do but don't copy their code. The thought is to read the code and UNDERSTAND it and by understand it I mean understand why that line(s) of code is written that way and what it does exactly. Plus you can pick up on others mistakes in their code and understand why its wrong so you don't make the same mistakes.

Link to comment
Share on other sites

Valid point carlito.. But its also worth mentioning sometimes the way other code is done is the best possible way to achieve a goal. Hundreds of thousands of coders in the world, and only so many ways to write code to work. Thats why you can't copyright code for the most part, you can copy right the concept of what the code does and what it was built for but the code itself not really cause if someone hasn't yet come up with a concept similar to anything anyone has done, someday sometime in the future someone will wanna do something entirely different that will look act and feel like what youve done :-)

 

but reading through and trying to understand what your pillaging is always a good thing to do..

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.