Still green in php but I'm liking it. Anyways...
I have a table that retrieves information from my db which gets its data from a date search, so I want it to be retrieved in another table after being filtered.
I tried a couple of things including passing the variable that is being used in filtering it (date) into another window so that the table retrieves this information there with id as date from previous page.
On my search page i have this:
<?php
$tester = $_POST['Date'];
mysql_select_db($database_dbconnkk, $dbconnkk);
$query_equ = "SELECT * FROM daily_reports WHERE Date = '$tester' ORDER BY id ASC";
?>
And a table that repeats the same which is working.
I have a link that opens window to this page with an attempt to retrieve data from previous test.
<?php
$tester2 = $_Get['Date'];
Also tried passing Date as id:
(id=<?php echo $row_equ['Date']; ?>)
Suppose problem is here:
$tester2 = $_Get['Date'];
Variable names are case sensitive in PHP, so this line should look like:
$tester2 = $_GET['Date'];
instead. Everything else looks like it should work.
i got it. passed the date i was using on the filter in the same variable i was using to filter the records
?Date=<?php echo $tester; ?>
then on my new window i get the same into another variable(tester2)
$tester2 = $_GET['Date'];
select then echo in columns
$query_equ = "SELECT * FROM daily_reports WHERE Date = '$tester2' ORDER BY id ASC";
Related
I'm trying to retrieve a varchar value from my WordPress DB. I tried the following code without success. Also tried with get_results instead of get_row, my post just shows the HTML code without the "brand" value (PHP snippets are enabled). How can I show a scalar value from my DB in my posts, index..? Do I need to set up a connection again?
<?php
$db_brand = $wpdb->get_row( "SELECT brand FROM $wpdb->brands where id = 1" );
echo "<p>The brand in this post is {$db_brand}</p>";
?>
you get row, but need show column. use
<?php
$db_brand = (array)$wpdb->get_row( "SELECT brand FROM $wpdb->brands where id = 1" );
echo "<p>The brand in this post is {$db_brand['brand']}</p>";
?>
I am trying to search record in mysql based on date which is submitted hidden field in a form, but I haven't got any results from DB with given date, I know there is a record with the same date.
I have a following code:
$id = $_POST['pid']; //hidden field in form with sample value 1
$d = $_POST['d']; // hidden field in form with sample value 2014-12-17 18:25:58
$ch = $con->query('SELECT * FROM '.PATDMBILL.' WHERE pid='.$id.' AND pfid=0 AND date="'.$d.'"');
In DB date column is current time-stamp.
When I assign $d to this value '2014-12-17 18:25:58' it works but from submitting form it will not work.
So Where I am making a mistake ?
I hope I have cleared my situation properly.
Rewrite the code:
$id = $_POST['pid'];
$d = $_POST['d'];
$query = 'SELECT * FROM '.PATDMBILL.' WHERE pid='.$id.' AND pfid=0 AND date="'.$d.'"';
echo $query;
$ch = $con->query($query);
You will then be able to see if the query is actually formatted properly and fix any obvious issues. Unfortunately there isn't enough information to say what the solution is, but you should be able to copy and paste the echoed 'query' and paste it into the tool you use to build queries (eg phpmyadmin or sequel pro)
The problem may be occurring because of the time 18:25:58 . You can change the database field from timestamp to date and pass only date from $d using strtotime(date("Y-m-d", $d));
Say I have a database table titled "people" and under the column "names", I have "Bill", "Karen", and "Ted".
In my php file, I want to use just one template and using those rows, have a seperate page for each name (like "myfile.php?name=Bill"). From what I understand, I have to use GET, but I'm pretty still confused and inexperienced with that, so how would I go about obtaining my goal here?
If you want to make a page based of a name in the get variable use this.
This basicly takes the name and takes it to the database and selects all field pretaining to that name, then you echo out the varibles and place them where you want a such.
<?php
$name = $_GET["name"];//gets name value from your url that you supplied in your post
$con=mysqli_connect("127.0.0.1","db-username","db-pass","db-name");
mysqli_real_escape_string($con,$name);
$sql = mysqli_fetch_assoc(mysqli_query($con,"SELECT * FROM people WHERE names='$name'"));
$id = $sql['id'];//id would be a field in the people table
$age = $sql['age'];//age would be a field in the people table
echo '<h1>'.$name.'</h1>';
echo '<p>'. $id .'<br/>'. $ age .'</p>';
?>
I am trying to grab ad code from my database and echo it on to the page, but for some reason it is not showing up?
$getad = ("SELECT * FROM ads WHERE place='non-mobile' AND who='adbrite' ");
while($rows = mysql_fetch_array($getad))
{
$code = $rows['code'];
}
$ad1 = $code;
later down the page i print it like this.
<?php print $ad1 ?>
I think your problem is that you don't actually execute the query, you just have saved it in a variable ($getad) and then try to do a fetch af an array containing a string as I see it. If I remeber correctly you have to save you query in a variable, as you did, and then type
$getad = "SELECT * FROM ads WHERE place='non-mobile' AND who='adbrite' ";
$q = $db->query($getad);
// generate results:
while ($q->fetchInto($row)) {
//display or store
}
You should also include checks, for example that this code has extracted at least one row, or that database connection is working, etcetera.
Screenshot mysql:
If I want to use the data in column “sender name” or "subject" then i use code
include ("connect.php");
$model = mysql_query("SELECT * FROM entries WHERE entries_id='3' limit 1");
$profil = mysql_fetch_array($model);
echo $profil[sender_name];
echo $profil[subject];
but how to use other data that users enter and are located in the column “data”?
for example
in the column “data” there are fields City, Address, Phone,…
What code to use to insert just name of the city (in example: Berlin) ?
The value in the data column is serialized. To use it you must first unserialize it (see php.net - unserialize).
For example (using your logic, I'm pretty sure you don't need the limit part of this query.)
include ("connect.php");
$model = mysql_query("SELECT * FROM entries WHERE entries_id='3' limit 1");
$profile = mysql_fetch_array($model);
$data = unserialize($profile['data']); //This is now an array of the data
To see what the unserialized data looks like you can then do this
print_r($data);
And to use the unserialized data to get, say the value, you would do
echo $data[0]['value']; //This will print "Berlin" for entries_id = 3.