Note that there are some explanatory texts on larger screens.

plurals
  1. POphp and mysql, best practices
    primarykey
    data
    text
    <p>I started working with php and mysql today. Basically, what I have, is an empty page with pieces that I fill in from looking up an id in a database. So on my home page I have an url that looks like this: </p> <pre><code>&lt;a href="content/display.php?id=id1"&gt; </code></pre> <p>And then in my display.php I have this:</p> <pre><code>&lt;?php include '../includes/header.php'; $id = $_GET['id']; $mysqli = new mysqli('localhost','username','password','dbname'); if($result = $mysqli-&gt;query("SELECT * FROM portfolio WHERE id='".$id."'")) { while($row = $result-&gt;fetch_object()) { $head = $row-&gt;head; $img1 = $row-&gt;img1; $img2 = $row-&gt;img2; $img_url = $row-&gt;imgurl; $img_thumb = $row-&gt;imgthumb; $vid = $row-&gt;vid; $swf = $row-&gt;swf; $url = $row-&gt;url; $url_text = $row-&gt;urltext; $text = $row-&gt;text; } } else echo $mysqli-&gt;error; ?&gt; </code></pre> <p>It's a sparse table in that not all of those fields will have information (many might be null). Basically they contains file names and then in the html I have code that looks like this:</p> <pre><code>if(isset($img1)) { echo '&lt;img src="images/'.$img1.'" /&gt;'; } </code></pre> <p>A couple of questions,</p> <ol> <li>Is this the best way to do this?</li> <li>Everytime I visit display.php, I am reopening a database connection right? That can't be good...</li> <li>I chose to put the names of the files in the database, rather than entire path names, or even the actual files themselves, figuring that, if I change the name of the file I can go into the database and update it for the file I want to change. If I change the path, I can just change it once in the html. Is that the best idea?</li> </ol> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload