I've hit a little wall in something I'm trying to do.
I have a table, entitled 'projects', in a database in SQL.
My issue is that I can't seem to select every row in a specific column.
This is the code that I've got so far relevant to this question (keep in mind that '$conn' is the connection to the SQL database, and the include command on the second line is just to include that connection):
//CONNECTION FILE
include "../include/dbh-inc.php";
//ASSIGNING QUERY VALUES TO VARIABLES
$q1 = mysqli_query($conn,"SELECT pid FROM projects;");
$q2 = mysqli_query($conn,"SELECT ptitle FROM projects;");
$q3 = mysqli_query($conn,"SELECT plink FROM projects;");
//SETTING ARRAYS FROM VARIABLES
$ids = mysqli_fetch_array($q1);
$titles = mysqli_fetch_array($q2);
$links = mysqli_fetch_array($q3);
mysqli_close($conn);
file_put_contents("newtest.txt","$titles\n");
foreach($titles as $title) {
file_put_contents("newtest.txt","$title\n", FILE_APPEND); //Testing
}
if(count($ids) > 0) {
file_put_contents("TEST.txt","");
for($i = 0; $i < count($ids)-1; $i+=1) {
$count = count($ids);
$title = $titles[$i];
$id = $ids[$i];
$link = $links[$i];
file_put_contents("TEST.txt","$i: $title, $id ($count), $link\n",FILE_APPEND);
echo("
<div class=\"projlink\">
<a href=\"$link\" style=\"width:190px;height:90px\">
<h2>$title</h2>
</a>
</div>
");
}
}
else {
echo("
<h2>Nothing here currently!<br>Be patient!</h2>
");
}
Any thoughts?
Thanks! - Raphael
mysqliis significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_queryinterface. Before you get too invested in the procedural style it’s worth switching over. Example:$db = new mysqli(…)and$db->prepare("…”)The procedural interface is an artifact from the PHP 4 era whenmysqliAPI was introduced and should not be used in new code.