PHP - Php Variables In Mysql Query?
So, I'm working on a quiz system. The text and choices are stored in a MySQL database. I haven't gotten to the choices yet, I'm still having trouble with the text. Here's my code:
Code: [Select] $querytext = "SELECT text FROM quiz id = '$prob'"; $result = mysql_query($querytext) or die(mysql_error()); echo $result; Yes, I'm already connected and stuff, that's just the snippet. I made sure that $prob is 1. Here's the MySQL Error I'm getting: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= ''' at line 1 I've looked all over the web and through the MySQL/PHP section of a 991-page PHP book. What am I doing wrong? I bet that I really, really failed epicly this time, but I never catch my epic fails and have to ask questions about them in order to fix the problem. So please reply Similar TutorialsOk so I have this script which will take a propery formated .csv file and upload to my database. here's the part i need to know if it's possible. basically it puts a group of codes into the database but i need a field that will specify which user the code pertains to from another table. The most logical way to reference the user is with an id code; but short of having the user reference an id code to put in the csv file, is there anyway I can make a query that will INSERT INTO and upload the csv? here's my current code... <?php $tmpName = $_FILES['song_codes']['tmp_name']; include('database.php'); if($sc != ""){ mysql_query('LOAD DATA LOCAL INFILE \''.$tmpName.'\' INTO TABLE music_codes FIELDS ENCLOSED BY "\"" TERMINATED BY "," LINES TERMINATED BY "\n" ;') or die('Error loading data file.<br>' . mysql_error()); $var = @$_GET['q'] ; $trimmed = trim($var); $table = @$_GET['field']; $query="SELECT * FROM contacts WHERE @'table' contains @'trimmed' order by id"; $result=mysql_query($query); $num=mysql_numrows($result); Why wont this work? Zacron I am trying to run a mysql query to get the sum of a column. When I type out the column name it works. When the column name is stored in a variable it does not seem to work. Code: [Select] <?php $total = $_GET['total']; if ($order != "" && $total != ""){ $query2 = "SELECT SUM('.$type2.') FROM customers WHERE sched=1"; $result2 = mysql_query($query2) or die(mysql_error()); while($row = mysql_fetch_array($result2)){ echo "Total ". " = $". $row["SUM('.$type2.')"]; echo "<br />"; } } ?> Any Help would be appreciated. Here is my code: // Start MySQL Query for Records $query = "SELECT codes_update_no_join_1b" . "SET orig_code_1 = new_code_1, orig_code_2 = new_code_2" . "WHERE concat(orig_code_1, orig_code_2) = concat(old_code_1, old_code_2)"; $results = mysql_query($query) or die(mysql_error()); // End MySQL Query for Records This query runs perfectly fine when run direct as SQL in phpMyAdmin, but throws this error when running in my script??? Why is this??? Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= new_code_1, orig_code_2 = new_code_2WHERE concat(orig_code_1, orig_c' at line 1 If you also have any feedback on my code, please do tell me. I wish to improve my coding base. Basically when you fill out the register form, it will check for data, then execute the insert query. But for some reason, the query will NOT insert into the database. In the following code below, I left out the field ID. Doesn't work with it anyways, and I'm not sure it makes a difference. Code: Code: [Select] mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); Full code: Code: [Select] <?php include_once("includes/config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><? $title; ?></title> <meta http-equiv="Content-Language" content="English" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> </head> <body> <div id="wrap"> <div id="header"> <h1><? $title; ?></h1> <h2><? $description; ?></h2> </div> <? include_once("includes/navigation.php"); ?> <div id="content"> <div id="right"> <h2>Create</h2> <div id="artlicles"> <?php if(!$_SESSION['user']) { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $name = mysql_real_escape_string($_POST['name']); $server_type = mysql_real_escape_string($_POST['type']); $description = mysql_real_escape_string($_POST['description']); if(!$username || !$password || !$server_type || !$description || !$name) { echo "Note: Descriptions allow HTML. Any abuse of this will result in an IP and account ban. No warnings!<br/>All forms are required to be filled out.<br><form action='create.php' method='POST'><table><tr><td>Username</td><td><input type='text' name='username'></td></tr><tr><td>Password</td><td><input type='password' name='password'></td></tr>"; echo "<tr><td>Sever Name</td><td><input type='text' name='name' maxlength='35'></td></tr><tr><td>Type of Server</td><td><select name='type'> <option value='Any'>Any</option> <option value='PvP'>PvP</option> <option value='Creative'>Creative</option> <option value='Survival'>Survival</option> <option value='Roleplay'>RolePlay</option> </select></td></tr> <tr><td>Description</td><td><textarea maxlength='1500' rows='18' cols='40' name='description'></textarea></td></tr>"; echo "<tr><td>Submit</td><td><input type='submit'></td></tr></table></form>"; } elseif(strlen($password) < 8) { echo "Password needs to be higher than 8 characters!"; } elseif(strlen($username) > 13) { echo "Username can't be greater than 13 characters!"; } else { $check1 = mysql_query("SELECT username,name FROM servers WHERE username = '$username' OR name = '$name' LIMIT 1"); if(mysql_num_rows($check1) < 0) { echo "Sorry, there is already an account with this username and/or server name!"; } else { $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); echo "Server has been succesfully created!"; } } } else { echo "You are currently logged in!"; } ?> </div> </div> <div style="clear: both;"> </div> </div> <div id="footer"> <a href="http://www.templatesold.com/" target="_blank">Website Templates</a> by <a href="http://www.free-css-templates.com/" target="_blank">Free CSS Templates</a> - Site Copyright MCTop </div> </div> </body> </html> Can I use a variable inside an sql query to determine which table to select from? The 2 functions below do exactly the same thing, they're just selecting data from different tables. I'm not sure how I can do it. Maybe put a parameter in the function & use sprinf? // Output the page data function showpages() { db_connect(); $query = ("SELECT * FROM pages"); // can I change pages to a variable somehow? $result = mysql_query($query); $result = result_to_assoc($result); return $result; } // Echo the pricelist data into the pricelist form function show_pricelist() { db_connect(); $query = ("SELECT * FROM pricelist"); // Again, if pricelist can be a variable, then I need only 1 function $result = mysql_query($query); $result = result_to_assoc($result); return $result; } Hi, my query doesn't work, I've got a date field in my MySql table, I want to get results of all employees that was added in a certain period. My query doesn't work but as soon as I type in values in my query instead of variables it works, what am I doing wrong? Code: [Select] $date = date('Y/m'); $date1 = strtotime('-6 month'); $date2 = strtotime('-6 month'); echo date('Y', $date1); echo date('m', $date2); $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbname", $con); $sql = "SELECT * FROM detail WHERE year(engaged) > '$date1' and month(engaged) > '$date2'"; $result=mysql_query($sql); echo mysql_num_rows($result); I have a query that pulls 1 field with 20 rows of data. I need to assign each row to a different variable so that I can then display them in different locations on a page. I cannot make each row of data a different field because of other constraints. My data is very well normalized. I am using mysqli so something like the old mysql_result would be lovely! How can this be done without hitting my database 20 times? Thanks for the help. Hello there, i`m trying to figure out a way to reorder a query string depending on variables. So the url would have the following query: /result/index.php?page=Weissenfels+Clack+and+Go&tyre=155_70_12&option1=30_02&option2=43_02&v_t=car&options=2 It should depend what page they come from if the page is equal to option2 then option1 is op1 and option2 is op2 To make it myself easier i have converted some variables On every first two digits ie 43 from the 43_02 can have 13 different ending digits, ie _03 or _04 or _05 etc... So i have converted all 43_02 43_03 etc to one variable ie $chain1 or $chain2 which holds in this case 43 a 43 is equal to Weissenfels+Clack+and+Go in the index page i have included the following process. At the moment i can only use php coding, unfortunately no mysql atm thank you in advance. Code: [Select] <?php $tyre = $_GET['tyre']; // finds the tyre size $op1 = $_GET['option1']; // finds the first chain size if applicable $op2 = $_GET['option2']; // finds the second chain size if applicable $op3 = $_GET['option3']; // finds the third chain size if applicable $op4 = $_GET['option4']; // finds the fourth chain size if applicable $op5 = $_GET['option5']; // finds the fith chain size if applicable $op6 = $_GET['option6']; // finds the sixth chain size if applicable $op7 = $_GET['option7']; // finds the seventh chain size if applicable $op8 = $_GET['option8']; // finds the eighth chain size if applicable $options = $_GET['options']; $page = $_GET['page']; $error = $_GET['info']; $vehicle_type = $_GET['v_t']; // finds the vehicle type $b = "Weissenfels+WeissTech+Tecna"; $c = "Weissenfels+Clack+and+Go"; if (($op1 == "30_02") || ($op1 == "30_03")) { $chain1 = "m30"; } elseif (($op2 == "43_02") || ($op2 == "43_03")) { $chain2 = "m43"; } else echo "error"; switch ($page) { case (($page == $c) && ($chain1 == "m43")); $option1 = $op1; $option2 = $op2; break; case (($page == $c) && ($chain2 == "m43")); $option1 = $op2; $option2 = $op1; break; default; $option1 = $op1; $option2 = $op2; break; } if ($options=="1") // calculates the possible combination { // outputs the results include 'options_1.php'; // type the amount of possible chains in here ie options_3 options_4 etc } elseif ($options=="2") { // outputs the results include 'options_2.php'; // type the amount of possible chains in here ie options_3 options_4 etc } elseif ($options=="3") { // outputs the results include 'options_3.php'; // type the amount of possible chains in here ie options_3 options_4 etc } elseif ($options=="4") { // outputs the results include 'options_4.php'; // type the amount of possible chains in here ie options_3 options_4 etc } elseif ($options=="5") { // outputs the results include 'options_5.php'; // type the amount of possible chains in here ie options_3 options_4 etc } elseif ($options=="6") { // outputs the results include 'options_6.php'; // type the amount of possible chains in here ie options_3 options_4 etc } elseif ($options=="7") { // outputs the results include 'options_7.php'; // type the amount of possible chains in here ie options_3 options_4 etc } elseif ($options=="8") { // outputs the results include 'options_8.php'; // type the amount of possible chains in here ie options_3 options_4 etc } else echo "there is an error on process_action2"; ?> I'm restarting this under a new subject b/c I learned some things after I initially posted and the subject heading is no longer accurate. What would cause this behavior - when I populate session vars from a MYSQL query, they stick, if I populate them from an MSSQL query, they drop. It doesn't matter if I get to the next page using a header redirect or a form submit. I have two session vars I'm loading from a MYSQL query and they remain, the two loaded from MSSQL disappear. I have confirmed that all four session vars are loading ok initially and I can echo them out to the page, but when the application moves to next page via redirect or form submit, the two vars loaded from MSSQL are empty. Any ideas? I'm very new to this and really could use some help. I've got a Web app that has one form that collects data from the user and puts it into a mysql database and has another form that allows the user to select critiera to find records in the database and display them on the page. All this is working just fine, but now that my database is getting more data in it, I want to add functionality to display 10 records on a page with results page navigation links so the user can move forward and backward in the results set. This part is not working and I've put in echo statements to figure out what the code is doing. The problem I'm having is that when the selection critiera pulls more than 10 records from the database, the first page of results is correct per the selection criteria entered by the user on the select form. When the 'next' link is selected to review the second page of results, the query is executed again. But this time the form variables have been reset and the results now contains the entire contents of the db. The start record is set to look at the 11th instance of the results set, so the second page starts with the 11th record in the database instead of the 11th record in the original results set. The original select statement is built by determining which criteria is selected using $_POST against each form variable. How can I retain the form variables or the original select statement so the second execution of the select statement results in the same results set as the first? The other option that may be better is to retain the original results set and avoid re-executing the select statement altogether. But I don't know how to do that either. Any suggestions, code samples or adivice is much appreciated! Hi All! I've written up a script for my website. It\ is basically a virtual job quest. My queries are all correct it just isn't registering the variable for the session. It is $-SESSION[theid']. I want to be bale to use it in my table but I get an error. How do I write this in my SQL query for it to work. The page (when no errors), doesn't show my data. Here is my ocde: Code: [Select] <?php session_start(); include("config536.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <?php if(!isset($_SESSION['username'])) { echo "<ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content><content><center><font size=6>Messages</font><br><br></center></content>"; } if(isset($_SESSION['username'])) { echo "<nav>$shownavbar</nav><ubar><img src=/images/layout/player.gif><a href=status.php>$showusername</a>.......................<img src=/images/layout/coin.gif> $scredits</ubar><content><center><font size=6>Basic Quests</font><br><br>"; $startjob = $_POST['submit']; $jobq = "SELECT * FROM jobs WHERE username='$showusername'"; $job = mysql_query($jobq); $jobnr = mysql_num_rows($job); if($jobnr == "0") { ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="submit" name="submit" value="Start Job"></form> <?php } if(isset($startjob)) { $initemidq = "SELECT * FROM items ORDER BY RAND() LIMIT 1"; $initemid = mysql_query($initemidq); while($ir = mysql_fetch_array($initemid)) { $ids = $ir['itemid']; } mysql_query("INSERT INTO jobs (username, item, time, completed) VALUES ('$showusername', '$ids', 'None', 'No')"); $wegq = "SELECT * FROM items WHERE itemid='$ids'"; $weg = mysql_query($wegq); while($wg = mysql_fetch_array($weg)) { $im = $wg['image']; $nm = $wg['name']; $id = $wg['itemid']; } $_SESSION['theid'] = $id; echo "<font color=green>Success! You have started this Job!</font><br><br>Please bring me this item: <b>$nm</b><br><br><img src=/images/items/$im><br><br><br>"; echo $_SESSION['theid']; } if($jobnr == "1") { $finish = $_POST['finish']; $okgq = "SELECT * FROM items WHERE itemid='$yes'"; $ok = mysql_query($okgq); while($ya = mysql_fetch_array($ok)) { $okname = $ya['name']; $okid = $ya['itemid']; $okimage = $ya['image']; } echo "Where is my <b>$okname</b>?<br><br><img src=/images/items/$okimage><br><br><br>"; echo $_SESSION['theid']; ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="submit" name="finish" value="I have the Item"></form> <?php } } if(isset($finish)) { $cinq = "SELECT * FROM uitems WHERE theitemid='$_SESSION[theid]'"; $cin = mysql_query($cinq); $connr = mysql_num_rows($cin); if($connr != "0") { echo "<font color=green>Success! You have the item.</font>"; } else { echo "<font color=red>Error! You do not have my item!</font>"; } } ?> . I basically just want to know how I can set this session as a variable. Also..I have a user login on every page and I want to be able to destroy JUST THE "theid" session and NOT the username session. How would I do that too? thanks for the help in advance! Hey Guys, I have to insert some data in MySQL but it wont work . Please have a look. <?php // to values are set to empty $vatsim=""; $ivao=""; // values from form in other page are set if(isset($_POST["pilotid"])) $pilotid=$_POST["pilotid"]; if(isset($_POST["network"])) $network=$_POST["network"]; if(isset($_POST["vid"])) $vid=$_POST["vid"]; if(isset($_POST["pilot"])) $pilot=$_POST["pilot"]; // if value is that copy data in this value, otherways in that value if ($network == "IVAO") { $ivao="$vid";} if ($network == "VATSIM") { $vatsim="$ivao";} // connect db include(dbconnect.inc.php); // first sql to update some data in one table $sql = "UPDATE `360283`.`jos_users` SET `IPS` = \'1\' WHERE `jos_users`.`id` = \'$pilotid\'"; $result1 = mysql_query($sql); // 2nd sql to insert some data in other table $sql2 = "INSERT INTO `360283`.`IPS_Pilots` (`ID`, `Name`, `Hours`, `Flights`, `LastFlight`, `IVAO`, `VATSIM`, `Enabled`, `Rating`) VALUES ('$pilotid', '$pilot', NULL, NULL, NULL, '$ivao', '$vatsim', '1', '0');"; $result2 = mysql_query($sql2); // sql to check if it was succesful $sql3 = "SELECT * FROM `IPS_Pilots` WHERE `ID` = '$pilotid' LIMIT 0, 30 "; $result3 = mysql_query($sql3); $num3 = mysql_numrows($result3); // echo succesfull or not if (!$num3) { echo "Sorry, but I failed to apply this pilot."; } else { echo "Pilot succesfully applied."; } ?> Thanks Hi, I'm only just getting started with php and mysql but I like to go off the deep end. something is wrong with my script. it seems to work up untill it comes to the UPDATE part. It wont actually update the table and the mysql_affected_rows bit returns -1 I've searched for an explanation and can't find one. Can someone tell me what I'm doing wrong Thanks. //connect to mysql $con = mysql_connect("xxx","yyy","zzz"); if (!$con) { die('Could not connect: ' . mysql_error()); } //use the right database mysql_select_db("foo_bar"); //select all cancelled tickets $status_query = "SELECT * FROM jos_vm_orders where order_status = 'X'"; $status_result = mysql_query($status_query) or die(mysql_error()); while ($newArray = mysql_fetch_array($status_result, MYSQL_ASSOC)) { $order_id = $newArray['order_id']; $quantity_query = "SELECT * FROM jos_vm_order_item where order_id = $order_id"; $quantity_result = mysql_query($quantity_query) or die(mysql_error()); while ($newArray2 = mysql_fetch_array($quantity_result, MYSQL_ASSOC)) { $product_quantity = $newArray2[product_quantity]; $order_item_sku = $newArray2[order_item_sku]; echo ("$order_id cancelled $product_quantity tickets sku was $order_item_sku \n"); mysql_query("UPDATE LOW_PRIORITY jos_vm_product SET product_in_stock = product_in_stock + $product_quantity WHERE product_sku = $order_item_sku AND STR_TO_DATE($order_item_sku, '%Y-%d-%m') $quantity_query = "SELECT * FROM jos_vm_order_item where order_id = $order_id"; $quantity_result = mysql_query($quantity_query) or die(mysql_error()); while ($newArray2 = mysql_fetch_array($quantity_result, MYSQL_ASSOC)) { $product_quantity = $newArray2[product_quantity]; $order_item_sku = $newArray2[order_item_sku]; echo ("$order_id cancelled $product_quantity tickets sku was $order_item_sku \n"); mysql_query("UPDATE LOW_PRIORITY jos_vm_product SET product_in_stock = product_in_stock + $product_quantity) WHERE product_sku = $order_item_sku AND STR_TO_DATE($order_item_sku, '%Y-%d-%m') >= CURDATE()"); echo ("$product_quantity tickets released into $order_item_sku \n"); echo ("Affected rows "); echo (mysql_affected_rows()); echo ("\n"); } } mysql_free_result($status_result); mysql_free_result($quantity_result); mysql_close($con); ?> I have a table and the structure is Code: [Select] ID, UID, Site, Uname, PassI already have this <?php $result = mysql_query(sprintf("SELECT * FROM Logins WHERE UID = %d", $_COOKIE['UID_WatsonN'])); //check login table against cookie if(($num = mysql_num_rows($result)) > 0){ mysql_close(); ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th>ID</th> <th>UID</th> <th>Site</th> <th>Uname</th> <th>Pass</th> </tr> <center> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"ID"); $f2=mysql_result($result,$i,"UID"); $f3=mysql_result($result,$i,"Site"); $f4=mysql_result($result,$i,"Uname"); $f5=mysql_result($result,$i,"Pass"); ?> <tr> <td><?php echo $f1; ?></td> <td><?php echo $f2; ?></td> <td><?php echo $f3; ?></td> <td><?php echo $f4; ?></td> <td><?php echo $f5; ?></td> </tr> <?php $i++; } } ?> which only gets the data from that one person. What is in the table is usernames and passwords for diffrent sites and i want to take all the usernames and passwords and put them into variables to pass on to the login form. Two part question: 1) I have a MySql table called "lang_key", which will store all of the common text for a site, which will allow easy site modifications from the "non tech" admin. Now, I am creating a recordest that will pull the information from the table, and create a basic list of variables in php. For example: I connect to the database, and do a wildcard select. I can figure out how to set a basic php variable like the example below: Code: [Select] $query1 = "SELECT * FROM lang_key"; $result = mysql_query($query1); while($row = mysql_fetch_array($result)) { $template = $row['common_text']; } There are three fields in my lang_key table (unique_id, string_id, and common_text') What I want to do is take it a step further from the example and I want $template to be the value of "common_text" Where string_id = "curr_template" I hope this makes sense? I really just want to create my recordset and then populate the website with the recordset info. Part II Do you recommend that I use a lang_key database, or would it be simpler and more efficient to just create a lang page with static variables, and use the php file write option to update the page? Thanks!!! I am working on a simple web app in which I want to store about 20 variables in a MYSQL table so when I hand off the project the variables can be easily edited by the end user. Is it easy to store variables in a MYSQL table then query those and make them PHP variables? Really I just need to read a MYSQL table and pull two columns; AppOption and AppOptionValue then create PHP variables for each of the results making the AppOption the variable name and the AppOptionValue the value of said varible. Any Ideas? Thanks! Sean Hi All, I have done a select from my DB and the data contains a '. echo "<td><a class='btn btn-primary col-sm-12' data-toggle='modal' data-userid='" . $uid . "' href='#userModal' data-firstname='" . $ufn ."' data-lastname='". $uln."' data-email='" . $ue . "' data-accountlevel='" . $ualid . "' data-mobile='".$um ."'data-role='".$urid."' data-active-sheets='".$ename."'>Manage</a></td>"; outputs <a class="btn btn-primary col-sm-12" data-toggle="modal" data-userid="2" href="#userModal" data-firstname="Chelsea" data-lastname="Hockley" data-email="chelsea@hotmail.com" data-accountlevel="1" data-mobile="0774882" data-role="1" data-active-sheets="A new event,Chelsea" s="" event'="">Manage</a> the issue part data-active-sheets="A new event,Chelsea" s="" event'="" Should be data-active-sheets="A new event,Chelsea's event" How do i prevent the ' from causing me this issue? Hi there,
I have a table in a MySQL database where I keep a list of user privileges. I am trying to create variables where the name of variable matches the privileges in the table.
This is also known as variable variables (I think).
EDIT (17/07/2014 04:02 PM): This might be a better way to describe what I'd like, so if the value from the table is admin_panel I'd like to dynamically create a variable with that name.
I have created a code so far, but all I seem to be getting is a list of Notice errors telling me that the variable is undefined. (I have supplied a list of errors a bit further down the post).
Here is the code:
<?php $host = "localhost"; $account = "***"; $password = "****"; $dbname = "****"; $connect = mysql_connect($host,$account,$password) or die("Unable To Connect"); $db = mysql_select_db($dbname,$connect) or die("Unable To Select DB"); $perm_query = "SELECT * FROM `privileges`"; $permission_query = mysql_query($perm_query); while($row = mysql_fetch_array($permission_query)) { $rows[] = $row; } foreach($rows as $row) { ${$row['privilege']}; } ?>The list of errors: Notice: Undefined variable: admin_panel in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: create_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: edit_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: delete_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: create_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: edit_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: delete_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: view_log in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: log_settings in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: password_change in C:\xampp\htdocs\DynamicVariables.php on line 20 Thanks Edited by chrisrulez001, 17 July 2014 - 10:05 AM. This is my current code (actually it's heavily based off of a code a fellow phpfreak made. Basically, this makes it easy to put up images. When I want to put up a linkable image, I simply need to add to the image_links my subfolder, and add to the image_description my description. Anyways, here it is, you can try and run it yourself: Code: [Select] <?php $rows_per_page = 2; $cols_per_page = 2; $image_href = '<a href=/'; $image_links = array('otherstuff/nature>', 'otherstuff/volcanoes>', 'otherstuff/papersupplies>''); $img_srcs = '<img src="https://s3.amazonaws.com/imgs/'; $images = array(); for($i = 1; $i < 10; $i++) { $images[$i] = $i; } $image_ending = '.png" height="200" width="200" /></a>'; $image_break = '<br /><div class="timeago"><div id="submitted">submitted </div>'; $image_descriptions = array('<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>'); $total_images = count($images); $images_per_page = $rows_per_page * $cols_per_page; $total_images = count($images); $total_pages = ceil($total_images / $images_per_page); $current_page = (int) $_GET['page']; if($current_page<1 || $current_page>$total_pages) { $current_page = 1; } //Get records for the current page $page_image_links = array_splice($image_links, ($current_page-1)*$images_per_page, $images_per_page); $page_images = array_splice($images, ($current_page-1)*$images_per_page, $images_per_page); $page_image_descriptions = array_splice($image_descriptions, ($current_page-1)*$images_per_page, $images_per_page); $slots = "<table border=\"0\">"; for($row=0; $row<$rows_per_page; $row++) { $slots .= "<tr>"; for($col=0; $col<$cols_per_page; $col++) { $imgIdx = ($row * $rows_per_page) + $col; $img = (isset($page_images[$imgIdx])) ? "{$image_href}{$page_image_links[$imgIdx]}{$img_srcs}{$page_images[$imgIdx]}{$image_ending}{$image_break}{$page_image_descriptions[$imgIdx]}" : ' '; $slots .= "<td class='tables'>$img</td>"; } $slots .= "</tr>"; } $slots .= "</table>"; //Create pagination links $first = "First"; $prev = "Prev"; $next = "Next"; $last = "Last"; if($current_page>1) { $prevPage = $current_page - 1; $first = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page=1\">First</a>"; $prev = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page={$prevPage}\">Prev</a>"; } if($current_page<$total_pages) { $nextPage = $current_page + 1; $next = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page={$nextPage}\">Next</a>"; $last = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page={$total_pages}\">Last</a>"; } ?> <html> <title></title> <head><style type="text/css"> #submitted {color: #888888; font-family:Verdana, Geneva, sans-serif; font-size: .8em; float:left;} .tables {padding-left: 20px; padding-right: 20px;} .timeago {color: #888888; font-family:Verdana, Geneva, sans-serif; font-size: .8em; float:right;} </style><script src="/static/jquery-1.5.1.js" type="text/javascript"></script> <script src="/static/jquery.timeago.js" type="text/javascript"></script> <script type="text/javascript"> jQuery(document).ready(function() { jQuery("abbr.timeago").timeago(); });</script></head> <body> <h2>Here are the records for page <?php echo $current_page; ?></h2> <ul> <?php echo $slots; ?> </ul> Page <?php echo $current_page; ?> of <?php echo $total_pages; ?> <br /> <?php echo "view mo {$next}"; ?> </body> </html> --------------------------------------------------------------------- Now, I want to prepare for the long run. If I ever get up to say 1000 images, it's gonna take a while to parse 1000 image_links and 1000 image_descriptions, so instead, I want it to be read off of a database instead. I know low-level mySQL, I can usually understand the syntax. My problem is, I can never wrap my head around the logic. You can lock me in a week for a week and I still wouldn't be able to figure it out. But show me the code, and I'd say "I get it!" Can anyone please help me out, rather by giving a rough code or good thorough advice to carry it out? I'd prefer a good rough code but I'll take anything at this point :[ Thanks! MOD EDIT: [code] . . . [/code] tags added. |