[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

use a php function and not exclusively mysql for my learning

Posted on 2014-02-17
4
Medium Priority
?
361 Views
Last Modified: 2014-03-06
using mysqli, or pdo

I would like a php function that prepends 'begin' and postpends 'end' to an existing varchar field

table.column1 int primary key autoincrement
table.column2 varchar
table.column3 varchar


example output
5454  begin5454end
656    begin656end
4        begin4end
A        beginAend


while this can be done with only mysql

UPDATE table SET column3 = CONCAT("begin",column2,"end")

I would like to use a php function so I can learn php functions.
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39865544
Untested code, but probably OK  in theory:

<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);

// A STARTING STRING
$old = '5454';

// IN OPEN CODE
$new = 'begin' . $old . 'end'; 

// WITH A FUNCTION
function pend($str, $alpha = 'begin', $omega = 'end')
{
    return $alpha . $str . $omega;
}

// VIA A FUNCTION CALL
echo pend($old);

Open in new window

0
 

Author Comment

by:rgb192
ID: 39865549
but how would this work with a select and update

making sure to update the correct row.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39865569
You would SELECT the column with the AUTO_INCREMENT id (Primary key) and the column you wanted to add information to.  With each row of the results set you would use the pend() function to change the column you wanted to add information to.  Then you would UPDATE the table, SET column you wanted with new information WHERE the id matched, LIMIT 1.
0
 

Author Closing Comment

by:rgb192
ID: 39911432
okay this is an example of a mysql connection and php function combined.

Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question