Darkwoods
-
Posts
88 -
Joined
-
Last visited
Posts posted by Darkwoods
-
-
Im trying to parse/convert this string using delimiters = , |
$text = 'cat1=hello,world|cat2=one,two|cat3=value1,value2';
Into an array like this:
Array( [cat1] => Array ( [0] => hello [1] => world ) [cat2] => Array ( [0] => one [1] => two ) [cat3] => Array ( [0] => value1 [1] => value2 ) )
any suggestion on how to achieve this ?
-
hey thanks I know it looks awful that because I am total noob
I'm still having problem with displaying the name of the category please if anybody can help me out with it would be great I have been stuck with this for a while now..
<?PHP $result = mysql_query("SELECT a.*, b.c_id, b.c_title FROM properties AS a JOIN cat AS b ON SUBSTRING_INDEX(a.pr_category, ',', 1) = b.c_id",$connect); while($row = mysql_fetch_assoc($result)) { $cat_name = $row["c_title"]; $cat_id = $row["c_id"]; $categories = explode(',', $row['pr_category']); /*test*/ foreach ($categories as $category) { list($cat_id, $cat_name) = explode('=', $category); echo '' . $cat_id . ':' . $cat_name . ''; } } ?>
-
I cant figure this out I have been searching and searching with no luck
-
Hey in my category field I got multiple values in the same mysql row
I'm having problem with how to separate them so I can display the name of the category and make a link for each category..
the multiple values are something like that 1,2
how can I make it so it would separate after each comma?
<?PHP $result = mysql_query("SELECT a.*, b.c_id, b.c_title FROM properties AS a JOIN cat AS b ON a.pr_category = b.c_id",$connect); while($row = mysql_fetch_assoc($result)) { ?> <h2><a href="blog-post.php?id="><?php echo $row['pr_title']; ?></a></h2> <p class="date">12 July 2011 in <a href="index.php?id<?php echo $row['c_id']; ?>"><?php echo $row['c_title']; ?></a></p> <img class="img-large-bg" src="../uploads/images/<?php echo $row['f_img']; ?>" alt="" title="" /> <?PHP } ?>
-
Try running:
SELECT a.*, b.title FROM properties AS a JOIN categories AS b ON a.pr_category = b.id
I would suggest running that query inside your database management software (phpMyAdmin), or the console, to make sure it returns the data you expect. This will save you coding time.
Hey your code worked but my remaining problem is how do I display the name of multi categories for example in the mysql field I got 1,2 which are cat1 and cat2
so far I'm only seeing the name of one category
-
Hey I'm trying to display the names of the categories but the values are numbers connected to another table with the title of the category
and the other problem is that sometimes it is multi categories selected and this will make a value like 1,2 so how can I solve this please?
here is my messed up code and there seems to be something wrong with it..
<?PHP $result = mysql_query("SELECT * FROM properties, categories ",$connect); while($row = mysql_fetch_assoc($result)) { $pr_category = $row["pr_category"]; ?> <h2><a href="blog-post.html"><?php echo $row['pr_title']; ?></a></h2> <?PHP $result = mysql_query("SELECT * FROM categories WHERE id='$pr_category' ",$connect); while($row = mysql_fetch_assoc($result)) { $cat_title = $row["title"]; ?> <p class="date">12 July 2011 in <a href="#"><?php echo $cat_title; } ?></a></p> <img class="img-large-bg" src="../uploads/images/<?php echo $row['f_img']; } ?>
-
I'm guessing what you mean is, that you have something that drives how many tabs you need. If so, you should make a function that outputs the tab code, and generates the id based on a counter in the loop. Inside that function the div would be something like:
function makeTab($id, $img, $h1, $para) { $out = '<div id="fragment-' . $id . '" class="ui-tabs-panel"> <img src="assets/img/' . $img . '" title="" // etc return $out; }
Hey thanks for your reply but this wont solve the problem the jQuery tabs im using is for news posts so the fragment tabs have to be the same 1,2,3,4 it wont work with id.
is there a way to tell the mysql to echo the latest second or third or forth post?
this way I can echo it in every fragment..
-
Hello I got an jQuery tabs and every tab got ID "fragment-1", "fragment-2" and so on
now if want to tell PHP to use fragment-2 if fragment-1 is taken how do I do that?
Thanks
<div id="fragment-1" class="ui-tabs-panel">
<img src="assets/img/image1.jpg" title="" alt="" />
<div class="info" >
<h1><?php echo $row['pr_title']; ?></h1>
<p>blabla..</p>
</div>
</div>
-
ah thanks that's how i did it
<?php echo substr($news_title,0,25); ?>
thanl for helping me out...
-
Hey...
I'm trying to echo the title of the news in the right column but I just want to display maximum of 25 characters how can I do it?
thanks
-
thank youu
this worked very well.. thanks again
-
Hey im having troube making this code as i have no idea how to do it...
basically what im trying to do is for example if the index.php?id=XXX i want to echo "this" and if it is just index.php i want to echo "that"
your help would be nice thanks
<?php $id_lang = $_GET['id']; if($id_lang == $id_lang){ $result = mysql_query("SELECT * FROM pages WHERE id='$id_lang' ",$connect); while($row44 = mysql_fetch_assoc($result)) { $js_langdir = $row44['lang_dir']; }} else{ $js_langdir = "LTR"; } ?>
-
hey thanks for your help guys
im using TinyMCE now so it is working fine thanks for your help anyway
-
i tried addslashes() but it is still the same
magic_quotes_gpc() is on know and it didn't change anything
yeah there is a DB connection the data is getting to the mysql but for example if i try to add text such as ( The whatever ‘Countdown’ will begin now!) the text will cut and will only get (The whatever) to the database
Have you made a DB connection at that point?
Try this and see if it makes a difference:
$name = mysql_real_escape_string($_POST['name'], $connect);
-
i just fixed the $_SERVER['PHP_SELF'] thanks for the advice
i added
if( isset($_POST['name']) ) { $name = mysql_real_escape_string($_POST['name']); }
but i'm still having problem with bypassing characters which are not supported such as ‘ it is sending the data to the mysql now unlike before but it cuts the text if there is an ‘
what should i do?
thanks
-
Hey I wasn't able to add/edit some text to the mysql database because of some character
how can i bypass them
should i use the mysql_real_escape_string() ? if yes how do i make it work with the code i got?
thaks
<?php include "../configdb.php"; $id = $_GET['id']; if(isset($_POST['submit'])) { //global variables $name = $_POST['name']; $footer = $_POST['footer']; //run the query which adds the data gathered from the form into the database $result = mysql_query("UPDATE pages SET name='$name', footer='$footer' WHERE id='$id' ",$connect); echo "<b>Your Page have been edited successfully"; // echo "<meta http-equiv=Refresh content=2;url=index.php>"; } elseif($id) { $result = mysql_query("SELECT * FROM pages WHERE id='$id' ",$connect); while($row = mysql_fetch_assoc($result)) { ?> <h3>::Edit Page</h3> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $row['id']?>"> <input type="hidden" name="id" value="<?php echo $row['id']?>"> <textarea name="name"><?php echo $row['name']?></textarea> <input name="footer" size="40" maxlength="255" value="<?php echo $row['footer']?>"> <input type="submit" name="submit" value="Submit"> <?php } } ?>
-
thanks this is great
-
Hey in my edit page i have 2 radio buttons in my form and i need to make sure the same value is still selected how can i do that?
thanks
-
loool thanks
I missed it lol and i have been on it for hours
but thanks
-
Hey i keep getting undefined index error when i submit the editing page I cant figure out what the problem is I have checked if i have miss spelled anything from the mysql table and i haven't please help everything exist in mysql but still im getting this error and not letting me update it
Notice: Undefined index: uruklink in D:\wamp\www\admin\edit.php on line 8
Notice: Undefined index: ketabsetlink in D:\wamp\www\admin\edit.php on line 9
<?php include "../configdb.php"; $id = $_GET['id']; if(isset($_POST['submit'])) { //global variables $uruklink = $_POST['uruklink']; $ketabsetlink = $_POST['ketabsetlink']; //run the query which adds the data gathered from the form into the database $result = mysql_query("UPDATE softlinks SET uruklink='$uruklink', ketabsetlink='$ketabsetlink' WHERE id='$id' ",$connect); echo "<b>Your Page have been edited successfully"; // echo "<meta http-equiv=Refresh content=2;url=index.php>"; } elseif($id) { $result = mysql_query("SELECT * FROM softlinks WHERE id='$id' ",$connect); while($row = mysql_fetch_assoc($result)) { $uruklink = $row['uruklink']; $ketabsetlink = $row['ketabsetlink']; ?> <h3>::Edit Page</h3> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $row['id']?>"> <input type="hidden" name="id" value="<?php echo $row['id']?>"> <input name="name" size="40" maxlength="255" value="<?php echo $uruklink; ?>"> <input name="footer" size="40" maxlength="255" value="<?php echo $ketabsetlink; ?>"> <input type="submit" name="submit" value="Submit"> <?php } } ?>
-
Hey there is no error with this code it works just fine but I would love to know if there is unnecessary coding in it for example do i have to do the global variables? is there a better way to do mysql editing page?
thanks
<?php include "../configdb.php"; $id = $_GET['id']; if(isset($_POST['submit'])) { //global variables $name = $_POST['name']; $footer = $_POST['footer']; //run the query which adds the data gathered from the form into the database $result = mysql_query("UPDATE pages SET name='$name', footer='$footer' WHERE id='$id' ",$connect); echo "<b>Your Page have been edited successfully"; } elseif($id) { $result = mysql_query("SELECT * FROM pages WHERE id='$id' ",$connect); while($row = mysql_fetch_assoc($result)) { $name = $row['name']; $footer = $row['footer']; ?> <h3>::Edit Page</h3> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $row['id']?>"> <input type="hidden" name="id" value="<?php echo $row['id']?>"> <input name="name" size="40" maxlength="255" value="<?php echo $name; ?>"> <input name="footer" size="40" maxlength="255" value="<?php echo $footer; ?>"> <input type="submit" name="submit" value="Submit"> <?php } }
-
oh I see what you mean now..
I will look into it but im still a total n00b lol anyway thanks
-
sorry i didn't get what you mean
at the moment I have it this way:
index.php?id=1 will show the English content from the database
index.php?id=2 will show the Spanish content from the database..
I know this wouldn't be good if you got more than one page website...
-
thanks this worked out really good as thrope made it
I was hoping to do it without having to redirecting it
thanks for both of you..
actually im doing a multiple language page so that would be the easiest way for me to do it
for example id 1 would be English id 2 would be Spanish etc
How to convert text string into associative array using delimiters?
in PHP Coding Help
Posted
Yes this is how I managed to do it but not so sure if it looks good..
but it works
$text = 'cat1=hello,world|cat2=one,two|cat3=value1,value2'; $arr= explode('|', $text); foreach($arr as $value) { $key = rtrim(stristr($value, '=', true), '='); $values = ltrim(stristr($value, '='), '='); $values = explode(',', $values); $array[$key] = $values; } print_r($array);