Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 02-04-2022, 09:41 PM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
How to add an SQL querie to data in SQL table?

Is this possible to do?

I have some HTML stored in a database and I want to add a query to the HTML code that gets pulled when it gets displayed on a page, is this possible to do? Im not finding anything on Google so I'm thinking it might not be?

If not, are there any alternates to storing a query in a database and pulling it through SQL other than including the query itself in an include.php file and inserting that into the .php page?

Basically, pulling one sql querie that includes another in the data that is being pulled, if that makes sense?
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 12:00 AM   #2
brassmonkey
Pay It Forward
 
brassmonkey's Avatar
 
Industry Role:
Join Date: Sep 2005
Location: Yo Mama House
Posts: 76,984
stackflow for free fast help
__________________
TRUMP 2025 KEKAW!!! - The Laken Riley Act Is Law!
DACA ENDED - SUPPORT AZ HCR 2060 52R - email: brassballz-at-techie.com
brassmonkey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 02:51 AM   #3
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
Quote:
Originally Posted by Publisher Bucks View Post
if that makes sense?
Unfortunately, none of what you wrote makes any sense
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 03:02 AM   #4
EddyTheDog
Just Doing My Own Thing
 
EddyTheDog's Avatar
 
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
Damn - That gave me a headache - You need to start that chapter again ...
EddyTheDog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 03:20 AM   #5
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
index.php - pulls header.php as an SQL query.
header.php - is a blank page that contains an SQL query to pull the html code from a database.

Can I include another SQL query in the header.php HTML even though the code is stored in the SQL database, not in the actual header.php file.

I know that I can include an SQL query in a regular server side php include, that contains HTML code, not an SQL query to pull the HTML code.

Can I do the same thing pulling the code out of my SQL database?

Quote:
<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<title>Untitled 1</title>
</head>

<body>
<?php
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM Table WHERE Body != '' LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
echo "";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "".$row["Body"]."";
}
echo "";
} else {
echo "0 results";
}$conn->close();
?>
</body>

</html>
In the SQL table 'body' contains this:

Quote:
<a href="urldotcom">keyword</a>
Can I have it (the body data in the table) include the following:

Quote:
<a href="urldotcom"><?php
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM Table WHERE Keyword != '' LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
echo "";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "".$row["Keyword"]."";
}
echo "";
} else {
echo "0 results";
}$conn->close();
?></a>
An SQL query inside an SQL query in effect?

It doesnt work when I do it like that, but its entirely possible I'm not using the right method of calling the 2nd query, if it is even possible.
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 04:49 AM   #6
Klen
 
Klen's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Little Vienna
Posts: 32,235
You want to pull code from SQL ?
Klen is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 05:41 AM   #7
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
I've re-read this like 5 times, and I still don't know what you are trying to accomplish.
Are you asking if you can store PHP code within a mysql database column? Yes, you can. This is an absolutely terrible idea, but yes, it can be accomplished using eval().

I am unable to determine from your post what your end goal is but if eval() is the solution to your problem, then you need to take a step back and redesign this. You should not be storing SQL queries or PHP code in a mysql column.

Please explain what you are trying to actually do, without any of your code examples.
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 05:50 AM   #8
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
Again I have no idea what you are doing and why you are even using loops if you are doing LIMIT 1, but maybe this will steer you in the right direction.

PHP Code:
<?php
$servername 
"localhost";
$username "user";
$password "pass";
$dbname "db";
$conn = new mysqli($servername$username$password$dbname);
if (
$conn->connect_error) {
    die(
"Connection failed: " $conn->connect_error);
}

$result $conn->query("SELECT * FROM Table WHERE Body != '' LIMIT 1");
if (
$result->num_rows 0) {
    while(
$row $result->fetch_assoc()) {
        
$sresult $conn->query("SELECT * FROM Table WHERE Keyword != '' LIMIT 1");
        while(
$srow $sresult->fetch_assoc()) {
            echo 
"<a href=\"urldotcom\">".$srow['Keyword']."</a>";
        }
    }
} else {
    echo 
"0 results";
}
?>
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 06:11 AM   #9
ZTT
Confirmed User
 
ZTT's Avatar
 
Industry Role:
Join Date: Apr 2019
Posts: 657
I like PB, and some of his help threads are reasonable, but I don't know why anyone bothers seriously replying to parody level nonsense like this, where the only possible excuse is trolling, and it's not that.

What he wants is simple to understand, it's just so idiotic that it can't possibly be that. But it is.

If you don't know anything about MySQL, or even what a database is supposed to be for, the solution isn't being spoonfed more code to paste into the spaghetti monster you have already, inspiring a new thread tomorrow, it's to stop using it until you know how to use it.
__________________
__________________
ZTT is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 09:39 AM   #10
Klen
 
Klen's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Little Vienna
Posts: 32,235
Quote:
Originally Posted by ZTT View Post
I like PB, and some of his help threads are reasonable, but I don't know why anyone bothers seriously replying to parody level nonsense like this, where the only possible excuse is trolling, and it's not that.

What he wants is simple to understand, it's just so idiotic that it can't possibly be that. But it is.

If you don't know anything about MySQL, or even what a database is supposed to be for, the solution isn't being spoonfed more code to paste into the spaghetti monster you have already, inspiring a new thread tomorrow, it's to stop using it until you know how to use it.
A challenge ?
Klen is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 11:37 AM   #11
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by k0nr4d View Post
Again I have no idea what you are doing and why you are even using loops if you are doing LIMIT 1, but maybe this will steer you in the right direction.

PHP Code:
<?php
$servername 
"localhost";
$username "user";
$password "pass";
$dbname "db";
$conn = new mysqli($servername$username$password$dbname);
if (
$conn->connect_error) {
    die(
"Connection failed: " $conn->connect_error);
}

$result $conn->query("SELECT * FROM Table WHERE Body != '' LIMIT 1");
if (
$result->num_rows 0) {
    while(
$row $result->fetch_assoc()) {
        
$sresult $conn->query("SELECT * FROM Table WHERE Keyword != '' LIMIT 1");
        while(
$srow $sresult->fetch_assoc()) {
            echo 
"<a href=\"urldotcom\">".$srow['Keyword']."</a>";
        }
    }
} else {
    echo 
"0 results";
}
?>
The code above was just copy & pasted to show what I was asking about, not the code I'm actually using, was just open in notepad lol


Basically, its for a makeshift CMS type admin area to manage a couple of sites via a crud system and on the external side of things, wanted to generate the pages using SQL outputs to save time (and be able to use predefined templates) but I also wanted to include a query in those templates to pull some niche specific data instead of having to hand code it into each template individually, I figured having that data stored in a seperate table and pulling it into the html code (stored in another table) would be the quickest way of doing that?
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 12:17 PM   #12
Why
MFBA
 
Industry Role:
Join Date: Mar 2003
Location: PNW
Posts: 7,230
i really dont know what the confusion was. i understood your question quite easily. i will however agree with someone above who said what you want to do is a terrible idea.

also, no one is going to write the code for you, unless you pay us. otherwise the best youll get is psuedo code or a link to more help. asking people to work for free is kinda silly, IMO. will you come do some random stuff for me for free?

youd be better off to save those templates to disk, as opposed to in a database, it will be quicker and cheaper.

what you want to do is perfectly possible youll just have to play with delimiting things correctly so they come in and out of the database correctly. but not recommended.
Why is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 12:22 PM   #13
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by Why View Post
i will however agree with someone above who said what you want to do is a terrible idea.
Can I ask why?

Quote:
also, no one is going to write the code for you, unless you pay us.
I'm not expecting to have the code written, that would just defeat the purpose of my learning to code myself

Pointers in the right direction are always appreicated, as are links to tutorials, etc.

The only way I'll learn is by doing things (and messing things up) myself
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 12:45 PM   #14
Why
MFBA
 
Industry Role:
Join Date: Mar 2003
Location: PNW
Posts: 7,230
templates will be faster to load(less work for the system) and safer, also a lot less complexity as you wont have to deal with the issues you are currently trying to solve.

what you what to do is quite literally the purpose of templating systems.

diving deeper into what you are doing....

you should never put sql credentials IN a file that is in a public directory. If PHP is broken for some reason in the future it would allow anyone viewing that page to see the database credentials. Always store credentials and other important stuff outside of the public directory and use an include to access it inside code that lives in public directory.
Why is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2022, 02:21 PM   #15
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
Quote:
Originally Posted by Publisher Bucks View Post
Can I ask why?
If you have php code in your db, and are running it via eval(), then any sql injection exploit (which there likely is, given you are new to this) will basically mean remote code execution.
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
query, sql, database, add, html, page, alternates, storing, pulling, file, inserting, include.php, including, .php, crap, displayed, stored, code, querie, data, table, pulled, thinking, google, finding



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.