PHP - Adding A Variable To The Beginning Of Another In A Db (concatenating?)
Hi,
I have two variables: $latest_note and $notes. Whenever I update $latest_note, I also want this (and today's date) to be added to $notes, such that $notes becomes a sort of archive of all of the latest notes, listed by date. I tried creating a third variable called $full_notes and saying $full_notes = $latest_note.$notes; ... then when I run my mysql update, I set notes='$full_notes' but it's not working properly. Is there a way to simply add one variable to the beginning of another in the db directly, concatenating the two? Thanks! Similar TutorialsI have a series of echo statements containing html and php elements. Is it possible to somehow store the following statements in one variable by concatenating and later print that variable. The variable should print out the statements as it is printing now. Code: [Select] <? echo "USER banned:<b>"; echo '<a style="text-decoration: none;" href="'.$forumurl.'1acpanel/user.php?do=edit&u='.$banuserid.'"<fontcolor="#4822aa" face="verdana" size="2">'.$banusername.'</font></a><br>'; echo "</b>USER Banned By:<b>"; echo '<a style="text-decoration: none;" href="'.$forumurl.'1acpanel/user.php?do=edit&u='.$banneruserid.'"><font color="#4822aa" face="verdana" size="2">'.$bannerusername.'</font></a><br>'; echo "</b>Banned on:<b>".$bandate."</b><br>"; echo "Reason:<b>".$reason."</b><br><br>"; ?> hi... i have a table ... i add and remove data in the table...when i add new record , information add to center of the table ! whats problem? i want add data in first of table. please guide me.thanks
I don't get why this fails. date() is meant to be a string, so why does it not concatenate correctly? Code: [Select] date_default_timezone_set('UTC'); $inputTime = date('c'); $inputTime = $inputTime . ' (UTC)'; // or $inputTime = date('c') . ' (UTC)'; Thanks. Hi all, I am trying to add the echo " AND "; below to the variable $model if the $_POST['purchasetype'] has a value. how can you add echos within IF statements to a variable, if at all possible? Many thanks, <?php if ($_POST[model] !="") { $model = "model='". $_POST['model'] ."'"; if ($_POST['purchasetype'] !="") { echo " AND "; } } else { $model = ""; } ?> SOLVED Hi im trying to set that if a certain statement is echoed then set variables to an amount but they dont seem to be inserting into the table Code: [Select] if ($match_qutoe == "".$username2." lands a uppercut"){ $points = "4"; $fighter = $username2; } $query = mysql_query("INSERT INTO fight (bluecornerusername, redcornerusername, round, fighter, points, statement) VALUES('$username', '$username2', '$round', '$fighter', '$points', '$match_quote')"); its only $points and $fighter that are not inserting Thanks The below might be a noob question but, I concatenate two spaces in the below string $new_hebrew_date_string = $hebrewMonthName . ' ' . $hebrewDay . "%"; yet when I execute echo "<br />new_hebrew_date_string is $new_hebrew_date_string<br />"; printf("hebrew_date_string is: %s <br />", $new_hebrew_date_string); Only one space is output in between $hebrewMonthName and $hebrewDay regardless of how many spaces I pad the string with. Strangely enough, the string $new_hebrew_date_string is correctly padded w/spaces when I pass it as a parameter to a mySQL stored procedure. Any ideas anyone? Thank you. Hi, I'm just starting PHP and I ran into a simple problem (that I can fix), but I just want to understand why my first approach doesn't work. I was testing multiplications and additions and the result I got was unexpected. Here is the code that doesn't work: Code: [Select] <?php $number1 = 5; $number2 = 10; print $number1." multiplied by ".$number2." + 1000 = ".$number1*$number2+1000; ?> Obviously, what I want as a result when I'm displaying the page is: "5 multiplied by 10 + 1000 = 1050" What I get: "1005". That's right, nothing else. On top of getting an erroneous answer, the sentence that's supposed to display right before the equation doesn't display at all. It's even worse if I switch it around like that: Code: [Select] print $number1." multiplied by ".$number2." + 1000 = ".1000+$number1*$number2; I get an error message and nothing displays. The obvious solution works: using a parenthesis at the beginning and at the end of the equation, which I should do regardless, but still, it's bugging me and since I just started learning PHP today, I want to understand how the code is compiled / interpreted so I don't make stupid mistakes like this one. Thanks in advance for the replies. I cant figure out how to add $recieved into this needs to take place of time hope someone knows how to do this what im doing is adding in the UNIX time i want to offset Code: [Select] <?php $offset = date('m/d/Y/H:i:s', time()+$send1['time_offset']); ?> I'm reading through this book which is actually not bad but, on page 286 there's a shopping_cart.php code (which I downloaded from the web site). The code that seems relevant to me is this: <?php $totalPrice = 0; foreach ( $_SESSION["cart"] as $product) { $totalPrice += $product->getPrice(); //<<<LINE 94 ?> The error I get is Fatal error: Call to a member function getPrice() on a non-object in C:\usr\web\shopping_cart.php on line 94 Should $product be a cast to the Product object? class Product { private $productId; private $productName; private $price; public function __construct( $productId, $productName, $price ) { $this->productId = $productId; $this->productName = $productName; $this->price = $price; } public function getPrice() { return $this->price; } //etc. } The below code returns a radio list after an input box in a profile edit section. All I want to do is add a space at the beginning of the radio list so to separate the input box and the radio list. Where the magic happens here is on this line: return $selhtml . ' ' . getFieldIcons( $_CB_framework->getUi(), $required, null, $fieldHandler->getFieldDescription( $field, $user, $output, $reason ), $fieldHandler->getFieldTitle( $field, $user, $output, $reason ) ); I've tried several variations of trying to use &nspb; both in the return string directly as well as creating a var for it. I've tried various ways of wrapping it in a div to simply add a margin, I've tried kicking my dog, I've tried banging my head against the wall, nothing seems to work. I either get a t var error, an unexpected something or other like . or & error depending on what I'm doing, or it tries to divide by zero using /'s. Here's a larger view of the code: function onFieldIcons( &$fieldHandler, &$field, &$user, $output, $reason, $tag, $type, $value, $additional, $allValues, $displayFieldIcons, $required ) { global $_CB_framework, $ueConfig, $_CB_fieldIconDisplayed; if ( is_object( $field->params ) ) { $privacyLevel = $field->params->get( 'plug_cbprivacy_level' ); } else { $privacyLevel = 0; } if ( $displayFieldIcons && ( $reason != 'search' ) ) { if ( ( $privacyLevel == 1 ) && ( $field->profile != 0 ) ) { $privacy =& moscomprofilerPrivacy::getInstance( $user, 'field', $field->fieldid ); $selected = ( $privacy ? $privacy->rule : '' ); $selectorName = $field->name . '___cbprivacy'; $connTypes = array(); if ( $this->params->get( 'conns_by_type', 0 ) ) { if ( $ueConfig['connection_categories'] ) { $connTypes = explode( "\n", $ueConfig['connection_categories'] ); foreach ( array_keys( $connTypes ) as $k) { $connTypes[$k] = trim( $connTypes[$k] ); } } if ( $selected == 2 ) { $type = $privacy->getParam( 'conn_cat' ); if ( $type ) { $selected = $selected . '|*|' . $type; } } } $options = array(); $options[] = moscomprofilerHTML::makeOption( '', '' . CBTxt::T(' ') ); if ( ( $ueConfig['allow_profileviewbyGID'] == -2 ) && $this->params->get( 'prop_registered', 1 ) ) { $options[] = moscomprofilerHTML::makeOption( '1', '' . CBTxt::T(' ' ) ); } if ( $ueConfig['allowConnections'] ) { $prop_connections = $this->params->get( 'prop_connections', 1 ); if ( $prop_connections ) { $options[] = moscomprofilerHTML::makeOption( '2', '' . CBTxt::T( ' ' ) ); } if ( count( $connTypes ) > 1 ) { foreach ($connTypes as $type ) { $options[] = moscomprofilerHTML::makeOption( '2|*|' . htmlspecialchars( $type ), ( $prop_connections ? ' ⌊ ' : '' ) . '' . sprintf( CBTxt::T( 'Only for %s' ), $type ) ); } } if ( $this->params->get( 'prop_fofs', 1 ) ) { $options[] = moscomprofilerHTML::makeOption( '3', '' . CBTxt::T( 'Also for friends of friends' ) ); } } if ( $this->params->get( 'prop_invisible', 1 ) ) { $options[] = moscomprofilerHTML::makeOption( '99', '' . CBTxt::T( ' ' ) ); } $selHtml = moscomprofilerHTML::radioList( $options, $selectorName, '', 'value', 'text', $selected, 2, false ); if ( isset( $_CB_fieldIconDisplayed[$field->fieldid] ) ) { return $selHtml; } else { $_CB_fieldIconDisplayed[$field->fieldid] = true; return $selHtml . ' ' . getFieldIcons( $_CB_framework->getUi(), $required, null, $fieldHandler->getFieldDescription( $field, $user, $output, $reason ), $fieldHandler->getFieldTitle( $field, $user, $output, $reason ) ); } } else { if ( isset( $_CB_fieldIconDisplayed[$field->fieldid] ) ) { return null; } else { $_CB_fieldIconDisplayed[$field->fieldid] = true; return getFieldIcons( $_CB_framework->getUi(), $required, $field->profile, $fieldHandler->getFieldDescription( $field, $user, $output, $reason ), $fieldHandler->getFieldTitle( $field, $user, $output, $reason ) ); } } } else { return null; } } The basic layout here is this: |inputbox||radio list| But I want: |inputbox| |radio list| $i = 0; while($i < 10) { if ($i == 7) { //Do Function } else { $i++ Go back to beginning of loop } //More if statements here. } Here is my current code to display files from the end to beginning : Code: [Select] <?php function func() { $date = date("Y-m-d"); $picarray = array(); $userarray = array(); $handle = opendir ('pqimages/'.$date.'/'); while (false !==($file = readdir($handle))) { if($file != "." && $file != "..") { $picarray[] = "http://blah.com/pqimages/".$date."/".$file.""; $userarray[]= "pqimages/".$date."/".$file.""; } } sort($picarray); sort($userarray); closedir($handle); $json_array = json_encode($picarray); echo $json_array; } func(); ?> How could I change this from end to beginning for ($picarray)? Cheers, George My first post.
I am trying to import images related to a particular listing ID. Currently, I have to enter the number of available photos into a db table, and run the following loop;
<section id="photos">
<?php
$b = $row['PIX'];
for ( $a = 01; $a <= $b; $a++ ) { echo "<a href=\"../imgs/{ $row[ 'ID' ] }-" . { $a } . ".jpg\" ><img src=\"../imgs/{ $row[ 'ID' ] }-" . { $a } . "_tn.jpg\" /></a> " ; } ?> </section> I would like to find a way to import all the images that begin with the $row[ 'ID' ], but without me having to enter/store { $b } (the number of images recorded in the db). How can I accomplish this? _ Hi, I've always used PHP code in my websites in a procedural manner as I come from a html/css background. Now that I want to do projects with more complexity I'm thinking I need to approach development in a more Object Oriented fashion. My question is more a theoretical one. I'm creating a User class and I'm not sure on what is the best practise for putting my functions etc. and where to call them. My project will have 2 different users (Admin & End User) so is it correct to say that the User class should encapsulate all the functions of both of these users ? By that I mean create/delete/modify user, login & change password/forgotten password functionality rather than having a seperate Login class Should I only call the database functions within these methods of the user class as opposed to calling them on the php page where the form data is posted ? For example, if a user logins in and when the form data is posted I currently open a connection, validate data, run the query. In an OO approach would I have just one User class method thats relevant to a particular page functionality ? Say, in pseudo code, for handling a login request loginRequest.php Code: [Select] include User class try { create new user User(); User::login(); } catch Exception() and should my User class look something like this class.User.php Code: [Select] include DBase class class User { var name, var email, var password, function validateInput (email, password) { if (!valid input) throw Exception else return true } function login (email, password){ try { database connection validateInput(); sql to see if user exists and login } catch Exception } } Apologies for this being a bit long winded! thanks tmfl Hello, I have this XML file I am parsing and I have hit a small formatting issue that I can't seem to get around.
Here is what the the output of the RSS looks like.
<description><![CDATA[<div style='text-align:left;'>Exit ramp closed. <br/><b>Current Status:</b> Open<br/><b>Affected Lanes:</b> Exit Ramp<br/><b>Dates:</b> Wednesday, May 28 - Thursday, May 29<br/><b>Days Closed:</b> <font color='#808080'>S</font><font color='#808080'>M</font><font color='#808080'>T</font><font color='#FF0000'><b>W</b></font><font color='#FF0000'><b>T</b></font><font color='#808080'>F</font><font color='#808080'>S</font> 20:00 PM - 6:00 AM</div>]]></description>Notice at the first is "Exit ramp closed." There is nothing before it but, for some weird reason when I parse it. It is on a new line like so, notice it should be up there with "Incident" but, it is dropped down below it. Incident: Exit ramp closed. Current Status: Open Affected Lanes: Exit Ramp Dates: Wednesday, May 28 - Thursday, May 29 Days Closed: SMTWTFS 20:00 PM - 6:00 AMThis is how it is formated in the td cell. <td style='{$td2Style}'><strong>Incident:</strong> {$incident_data_desc}</td>\n";So as you can see above, there is nothing before it that would cause it to break to a new line both in the table or in the RSS. So how can I remove that first return only is that is on the same line with it and not below it. I have tried this and a couple of other things like trim with no luck. $description = $item->description; $incident_data_desc = str_replace("\r", '', $description );Note, I only need that first one removed, the others are fine. I can do it but it will remove all the breaks and I only want to remove that first one that is causing the line to be on a new line. Any suggestions? -Thanks Hello guys, im using this code atm and it's working, but the new rows created are put in the end of the table. I want them to stack up from the beginning pushing older rows down. What should i do to make that work? <?php $con = mysql_connect("localhost","*****","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ananaz_se", $con); $sql="INSERT INTO stuff (adult, namn, url) VALUES ('$_POST[adult]','$_POST[namn]','$_POST[url]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 row added"; mysql_close($con) ?> This is my code: $episodes = mysql_query("SELECT * FROM episode_links WHERE episode_id = '".$episode_id."' AND moderated='1' ORDER BY host ASC"); while ($episode = mysql_fetch_assoc($episodes)) { // code here } and in my host table, I have values like this: Fileserve.com MegaUpload.com Rapidshare.com Torrent And I would like a way to sort this so that only the Fileserve links appear on the top ( the first few results), then all the others. can anyone help me? I keep getting errors that are associated with one-off and one-time occurrences. I want to tell the script to just restart itself from the beginning if it encounters any type of error, whether it by a fatal error, or any other kind. is there a way to do this? I have a regex that validates a string.
I want to ensure there is no space in the string.
Thus far I have used the negative look ahead regex construct as shown below to match strings without spaces.
(?!.*(\s))While this prevents space in between a word, all strings with space characters at the end or beginning are getting validated. I do not want that at all. This is the full regex script below: $string = "#JebiamgoOeing0"; if (preg_match('/^.*(?=.{8,})(?!.*([A-Za-z0-9])\1{1})(?=.*[a-z])(?=.*[A-Z])(?!.*(\s))(?=.*[\d])(?=.*[\W]).*$/', $string)) { "do something"; } else { "do something else"; }I need help in resolving this. Thank you. Edited by terungwa, 25 October 2014 - 12:50 PM. |