PHP - Selecting From Mysql Where Text = 'some_text' Help Pls
How can i use
$query = "SELECT * FROM klanovi WHERE naziv = '{$trazi}' OR tag = '{$trazi}'"; but i need to search from base where that $trazi is contained in naziv or tag, i mean like wildacards? And how can i search that text but no matter of lowercase or uppercase ? Similar TutorialsHi guys, essentially, I have very limited knowledge with mysql and have hit a brick wall. The row that I am trying to select is the following: Now, I am trying to use the following script to achieve that: Quote $query = "SELECT meta_value FROM wp_usermeta WHERE user_id='$id' & meta_key='simple_local_avatar'"; The $id is being passed as 1 from a cookie, and I know for sure that thats working properly, but I cant figure out the coding to select it correctly. I need the script to search for the ID of the user & then user the simple_user_avatar to find the right entry. Please someone cast your knowledge and help me out! Oh, little adendum. All that happens when the script runs is that the first row of the table is called out, which is: Hey guys, im trying to select only certain rows that matchs the address in a array. Not sure how to do this This is making the array $siege_check3 = "SELECT address FROM planets WHERE siege='".mysql_real_escape_string($_SESSION['goauld'])."'"; $siege_check2 = mysql_query($siege_check3) or die(mysql_error()); $arr = array(); while($siege_check1 = mysql_fetch_array($siege_check2)) { $siege_planets = $siege_check1['address']; $arr[] = $siege_planets; } Then I want to AND grab rows where defender_planet equals one of the address in the array above tried using in_array but telling me its not a valid function $alert3 = "SELECT * FROM travel WHERE defender_id = '" .($_SESSION['user_id'])."' AND stance = 2 AND stealth_tech < '".($stealth_tech)."' AND address= in_array(defender_planet,$arr) ORDER BY arrived_time DESC"; $alert2 = mysql_query($alert3) or die(mysql_error()); while($alert1 = mysql_fetch_assoc($alert2)) { } Hi Guys, I need a little help. This one is giving me a real head ache :-( I have created a archive database in mysql. Within the database there are tables named YYYYMMDD_var. The tables layout is as follows: #################################### node + T00 + T03 + T06 + T09 + T12 + T15 + T18 + T21 #################################### I have created some drop down menus in php to call for the dates Dateto and Datefr. I then calculate the diff between the dates and return the output (20101101_var, 20101102_var etc,,,) But when I call for the mysql Select I cant get all tables :-( This is the following code I have been using, starting from getting requesting the dates from the drop down menus. The problem lies in the UNION, where because it's caught in the loop, it returns it at the end of the line. Which creates the error. If anybody has any other ideas, please help :-) //dates from $dayfr = $_REQUEST['dayfr']; $monthfr = $_REQUEST['monthfr']; $yearfr = $_REQUEST['yearfr']; //dates to $dayto = $_REQUEST['dayto']; $monthto = $_REQUEST['monthto']; $yearto = $_REQUEST['yearto']; $var = $_REQUEST['var']; //cacluate the diff function days($date1, $date2){ $month1 = date("m", strtotime($date1)); $day1 = date("d", strtotime($date1)); $year1 = date("Y", strtotime($date1)); $month2 = date("m", strtotime($date2)); $day2 = date("d", strtotime($date2)); $year2 = date("Y", strtotime($date2)); $first = gregoriantojd($month1, $day1, $year1); $second = gregoriantojd($month2, $day2, $year2); $diff = abs($first-$second); return $diff; } $date1 = "$yearfr-$monthfr-$dayfr"; $date2 = "$yearto-$monthto-$dayto"; $days = days($date1, $date2); for($i=0; $i<$days; $i++){ $newdate = date("Ymd", strtotime("$date1 +$i days")); $datevar="$newdate$var ,"; $getdata="SELECT * FROM $newdate$var WHERE node='1' UNION "; echo "$getdata"; } //NOW SELECT OUR TABLES FROM THE ARCHIVE DATABASE $data=mysql_query("$getdata") or die(mysql_error()); Currently my code picks a random number between 1-6 then extracts that many (random) entries from a list in my database. My current code displays the whole array, how can I chop the array into 6 bits so I can output the data separately (up to 6 list items)? $con = mysql_connect("x","x","x"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("x", $con); $ran_x = rand(1,6); $appearance_query = "SELECT * FROM `x` ORDER BY RAND( ) LIMIT $ran_x"; $get_x = mysql_query($x_query); echo 'x(s): '; echo '<br />'; echo "<ul style='list-style:none;'>"; while($row = mysql_fetch_array($get_x)) { echo "<li>" . $row['x'] . "</li>"; } echo "</ul>"; echo "<br />"; mysql_close($con); Any help would be greatly appreciated, Thanks, otester Hi all, I am trying to get data from MySQL to display in a html table in TCPDF but it is only displaying the ID. $accom = '<h3>Accommodation:</h3> <table cellpadding="1" cellspacing="1" border="1" style="text-align:center;"> <tr> <th><strong>Organisation</strong></th> <th><strong>Contact</strong></th> <th><strong>Phone</strong></th> </tr> <tbody> <tr>'. $id = $_GET['id']; $location = $row['location']; $sql = "SELECT * FROM tours WHERE id = $id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { '<td>'.$location.'</td> <td>David</td> <td>0412345678</td> </tbody>'; } } '</tr> </table>'; Anyone got any ideas? Hi, basically, here's the deal: I have a lit of checkboxes that are added by the admin (there's an unlimited amount, just depends on how many are added). Then, those are put in a form, in which the user picks whichever ones need to be chosen and those values get sent to a MySQL table. Here's the code that displays the checkboxes Code: [Select] <?php $sql="SELECT * FROM category ORDER BY categoryID ASC"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ echo "<input type='checkbox' id='". $row['categoryName'] ."' name='licensed[]' value='" . $row['categoryID'] ."' /><label for='". $row['categoryName'] ."'><br>" . $row['categoryName'] ."</label><br>"; } ?> What I'm making now, is an edit form where whichever checkboxes were checked, will show up checked in the edit form. But I'm not really sure how to go about this, since there is only one actual input tag in the code, I can't select the different ones. I also have this SQL query which selects whichever boxes were inputted into the DB Code: [Select] $sql2="SELECT * FROM category, categoryInfo WHERE category.categoryID = categoryInfo.categoryID AND categoryInfo.parentID = $parentID"; $result2=mysql_query($sql2); Where $parentID is the ID of whichever form you're editing. But yes, I'm basically not really sure how to go about this and would like some help figuring this out Thanks for your time Hello. Many thanks for your help. I am writing a PHP/MySQL dating-site and have hit a programming impass. I have a database full of members and a search form consisting of checkboxes. So to search, a member ticks say...gender: female; age: 21,22,23,24,25,26; height: 5'4",5'5",5'6",5'7"; county: cornwall,devon,somerset How can a run a check on the database selecting all entries that fall into the selected criteria. For example a 23 year old female of 5'5" living in Cornwall and a 26 year old female of 5'4" living in Somerset? The key index of my database is 'id' and the fields a age,height,county The names of the form checkboxes a Gender: male, female; Age: 21,22,23,24 etc; Height: 5_4,5_5,5_6 etc; county: cornwall,devon etc I have the following code, and really can't see what is wrong with it. Any help would be great. <?php if (!mysql_connect('127.0.0.1', 'root', '')) { echo 'Could not connect to mysql'; exit; } $dbname = 'Requests'; $result = mysql_list_tables($dbname); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while($row2 = mysql_fetch_row($result)) { foreach ($row2[0] as $table_id) { $query = "SELECT * FROM $table_id"; $dbresult = mysql_query($query); // added code to use the tablename and select all records from that table // create a new XML document $doc = new DomDocument('1.0'); // create root node $root = $doc->createElement('mixes'); $root = $doc->appendChild($root); // process one row at a time while($row = mysql_fetch_assoc($dbresult)) { // add node for each row $occ = $doc->createElement($table_id); $occ = $root->appendChild($occ); // add a child node for each field foreach ($row as $fieldname => $fieldvalue) { $child = $doc->createElement($fieldname); $child = $occ->appendChild($child); $value = $doc->createTextNode($fieldvalue); $value = $child->appendChild($value); } // foreach } // while } } echo 'Wrote: ' . $doc->save("s.xml") . ' bytes'; // Wrote: 72 bytes ?> SELECT * FROM `booking_tbl` WHERE booking_status = 'Check In' AND departure_date_time = NOW()"I use the datetime datatype for the departure_date_time so i can get data from that data because it checking the date and time but i want it to check on the date from the datetime datatype So how can i get the data only with that date without the time in the mysql datetime datatype We recently upgraded from PHP4 to PHP5 and the below script that was working perfectly in 4 has completely stopped working and I can't figure out why for the life of me. I'm not an experienced PHP programmer--I've done some forms, but this is the first time I've used a database. What needs to (and was) happen: A user enters their username in the form and gets a readout of their participation so far that month. The problem(s): I know that it's storing the variable 'user' because it echoes it back properly, but the database is no longer allowing me to select the row based on that variable. I know it's not that I can't connect to the database because if instead of '$user' I change the code to a username I know is in there, I get the proper readout. This all started as soon as I transferred over to PHP5--before that, no problems at all. The database information is all correct, I just took it out for privacy's sake. <form id="feedback" method="post" action="index.php"> <input name="user" type="text" value="Enter user name" size="20" maxlength="50" /><br /> <input name="send" id="send" type="submit" value="Submit" /> </form> <?php if (isset($_POST['user'])) { $_session['user'] = $_POST['user']; } ?> <p>You entered your username as: <strong><? echo $_session['user'];?></strong>. If this is not correct or you do not see your information below, please re-enter your username and click Submit again.</p> <?php $con = mysql_connect("database","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $result = mysql_query("SELECT * FROM March WHERE Username='$user'") or die ('Error: '.mysql_error ()); while($row = mysql_fetch_array($result)) { echo "<table border='0'>"; echo "<tr>"; echo "<td><strong>Username:</strong> </td><td>" . $row['Username'] . "</td></tr>"; echo "<tr><td><strong>Mar. 2 Discussion:</strong></td><td>" . $row['Mar2Q'] . "</td></tr>"; echo "<tr><td><strong>Mar. 2 Poll:</strong></td><td>" . $row['Mar2P'] . "</td></tr>"; echo "<tr><td><strong>Mar. 9 Discussion:</strong></td><td>" . $row['Mar9Q'] . "</td></tr>"; echo "<tr><td><strong>Mar. 9 Poll:</strong></td><td>" . $row['Mar9P'] . "</td></tr>"; echo "<tr><td><strong>Mar. 16 Discussion:</strong></td><td>" . $row['Mar16Q'] . "</td></tr>"; echo "<tr><td><strong>Mar. 16 Poll:</strong></td><td>" . $row['Mar16P'] . "</td></tr>"; echo "<tr><td><strong>March Participation To-Date:</strong></td><td>" . $row['Participation'] . "</td></tr>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> ANY help would be greatly appreciated! I've got a couple hundred people who use this on a regular basis and are starting to ask why it's not working. I am trying to make a filter to show posts from mutual friends between you and the persons profile you're on, I have somewhat of an idea on how to write the mysql query (it needs to be just one query, not two(which would be the easy way of doing it)). the "friends" table has: "friend_1" and "friend_2" and the "posts" table: "to_id" and "from_id" The PHP variables would be: "$session" and "$id" id would be the users Id of the profile you're on. Thanks, any help would be appreciated. Hi I am trying to select and order data/numbers from a colum in a mysql data base however i run the code and it returns no value just a blank page no errors or any thing so i think the code is working right but then it returns no result? Please help thanks Here is the code: <?php $host= "XXXXXX"; $mysql_user = "XXXXXX"; $mysql_password = "XXXXXX"; $mysql_database = "XXXXXXX"; $connection = mysql_connect("$host","$mysql_user","$mysql_password") or die ("Unable to connect to MySQL server."); mysql_select_db($mysql_database) or die ("Unable to select requested database."); $row = mysql_fetch_assoc( mysql_query( "SELECT XP FROM Game ORDER BY number DESC LIMIT 1" ) ); $number = mysql_result(mysql_query("SELECT XP FROM Game ORDER BY number DESC LIMIT 1"), 0); echo "The the highest XP is $number"; ?> create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that hello all, i am hoping someone would be kind enough to help me. the form and code works fine, until i add a ' for e.g. michael's and when i click the submit i get this error: Error: 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 's','home')' at line 3. the mysql filed is set as text. the php code: Code: [Select] function content_add() { $sql="INSERT INTO content (title, body, page) VALUES ('$_POST[title]','$_POST[body]','$_POST[page]')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "<script>window.location='index.php?option=content'</script>"; } just hoping someone can help me fix this issue, thanks all. I am trying to add a txt file to a mysql database. Is there any one that can help? Here are the details TEST.TXT contains the following A001200910019999999900000200000000000000000000000 00000000000000000000000000 A002200910019999999900000610000000000000000000000 00000000000000000000000000 A003200910019999999900000687500000000000000000000 00000000000000000000000000 A004200910019999999900000335000000000000000000000 00000000000000000000000000 A005200910019999999900000626500000000000000000000 00000000000000000000000000 A006200704019999999900000423500000000000000000000 00000000000000000000000000 A007200910019999999900000323500000000000000000000 00000000000000000000000000 A008200704019999999900000102500000000000000000000 00000000000000000000000000 And so on up to 200 rows long I need to split each row the same way and add them to a table I will use the first row as an example Character 1 to 4 (A001) entered into a field called name Character 5 to 12 (20091001) entered into a field called efdate Character 13 to 20 (99999999) entered into a field called exdate Character 21 to 31 (00000200000) entered into a field called prfee Character 32 to 42 (00000000000) entered into a field called assfee Character 43 to 53(00000000000) entered into a field called spfee Character 54 to 64 (00000000000) entered into a field called anfee Character 65 to 75 (00000000000) entered into a field called nanfee Thanks in advance for the help I have a MySQL Longtext field. When I query the data using PHP, I cannot get all of the text. If there are 1000 characters, I only get about half. Does this have anything to do with packet-size? Is this a configuration thing? hello world! First post here! I'm a newbie trying to make my own cms, everything is working except the import of image into the post, this becomes text. Here is the code: Code: [Select] function connect() { $con = mysql_connect($this->host, $this->username, $this->password) or die (mysql_error()); mysql_select_db ($this->db, $con) or die (mysql_error()); } function get_content($id = '') { if($id != ""): $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; else: $sql = "SELECT * FROM cms_content ORDER BY id DESC"; endif; $return = '<a href="index.php">go back</a>'; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0): while($row = mysql_fetch_assoc($res)) { echo '<div class="title"><h1><a href="index.php?id=' . $row['id'] . '">' . $row['title'] . '</a></h1></div>'; echo '<div class="date"><p>' . $row['date'] . '</p></div>'; echo '<div class="photo"><p>' . $row['photo'] . '</p></div>'; echo '<div class="txt"><p>' . $row['body'] . '</p></div>'; } else: echo '<p class="results_">uH oh!</p>'; endif; echo $return; } function add_content($p) { $title = mysql_real_escape_string($p['title']); $date = mysql_real_escape_string($p['date']); $photo = mysql_real_escape_string($p['photo']); $body = mysql_real_escape_string($p['body']); // if they write wrong if(!$title | | !$body): if(!$title): echo "<p>The Title is Required</p>"; endif; if(!$photo): echo "<p>No photo</p>"; endif; if(!$body): echo "<p>The body is Required</p>"; endif; echo '<p><a href="add-content.php">Try again</a></p>'; else: // add to db $sql = "INSERT INTO cms_content VALUES (null, '$title', '$date', '$photo', '$body')"; $res = mysql_query($sql) or die(mysql_error()); echo "<p class='results_'>Added with success!</p>"; // [END] add to db endif; // [END] if they write wrong } and in the html i got a form Code: [Select] <form enctype="multipart/form-data" method="post" action="index.php"> <input type="hidden" name="add" value="true"> <div> <label for="title"><p>Title:</p></label> <input type="text" name="title" id="title" /> </div> <div> <input type="file" name="photo"><br> </div> <div> <label for="body"><p>Body:</p></label> <textarea name="body" id="body" rows="8" cols="40"></textarea> </div> <input type="submit" name="submit" value="Add Content"> </form> I have just started updating my wordpress website using PDO. For some unknown reason, grabbing text from mysql and using 'echo' to display the data does not work. Here is my code:
global $wpdb;
$symbol = get_query_var('name');
$result = $wpdb->get_row("SELECT about FROM wp_data WHERE symbol = '{$symbol}'");
echo $result->about;
I used a foreach loop and echoed all data and everything shows up except for the "TEXT" field (I only have one TEXT column).
Please help! Thanks in advance.
Hi all, I have implemented a WYSIWYG in my admin panel, here i can write text and customize it how i want it and then convert it to a html code and save it in my mysql database. Now I want to let other people see the text in the homepage, but it is showing this text very wrong functions like this Code: [Select] <p> <b> <strong> <font> arent working. For example I make text Code: [Select] <b>title</b> <strong> blabla bla bla </strong> then the text becomes like this litterly Quote "<b>title<b> <strong> blabla bla bla </strong> " the codes have no effect and are seen as text in the homepage. My question is how is this possible and how can i fix this, thanks. The code on my homepage is like this Code: [Select] <?php $tekst="SELECT * from homepage where id='1'"; $tekst2=mysql_query($tekst) or die("unable to connect"); $tekst3=mysql_fetch_array($tekst2); print "$tekst3[tekst]"; ?> Hi, Wonder if someone could help with the problem below. Got a main page that includes a header, footer and a link to a database. I can get the two Includes to work but can't seem to display the database fields in the body of the page. What has me baffled is that it appears to be connecting to the database, (Opening the connection to the database server The connection worked. The link is: Resource id #3) but no text (see below for database text) is appearing on the screen. Yet I'm not getting a "page_not_found" message. I can go to the database in MYSQL console and query it successfully. Read and (hopefully) applied the section Debugging: A Beginner's Guide, but still can't see the problem. Any help greatly appreciated. Bren --------------------CODE FOR MAIN PAGE START------------------- <?php $page_name = $_REQUEST['name']; /*http://localhost/exemples/page.php?name=about_us*/ // Get the body of the page mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $sql = "SELECT * from pages WHERE name='$page_name'"; print "Opening the connection to the database server<br>"; $link = mysql_connect("localhost","root", ""); print "The connection worked. The link is: $link <br>"; /* --------------What is being selected from the database-------------- +----------+------------------------------------------------------------------------+ | name | body | +----------+------------------------------------------------------------------------+ | about_us | <h1>About Us</h1> ACME Toys has been established in 1850 to provide toys | to children all over the world +----------+------------------------------------------------------------------------+ 1 row in set (0.00 sec) ---------------------------------------------------------------------- */ $result = mysql_query($sql) or die(mysql_error() ); // If the page is not found, redirect to a static page if(mysql_num_rows($result) == 0 ) { header("Location: page_not_found.html"); } $row = mysql_fetch_assoc( $result ); $body = stripslashes( $row["body"] ); // Include the header include("c:/wamp/www/exemples/header.php"); // Print the body of the page echo $body; // Include the footer include("c:/wamp/www/exemples/footer.php"); ?> --------------------CODE FOR MAIN PAGE END------------------- |