Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

using single and double quotoes

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

using single and double quotoes

Postby rashatanda » Mon Jun 10, 2013 6:05 am

Please help me check why this code is not working.

echo "<li><a href=\"content.php?subj=" . urlencode($subject["id"]) . "\">{$subject["menu_name"]</a></li>";
rashatanda
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Jun 10, 2013 6:01 am

Re: using single and double quotoes

Postby developerahusain » Mon Jun 10, 2013 9:21 am

I have corrected the problem. here is the revised code.Actually you put ' instead of " in the ending quote. You know ending and beginning quotes should be same. It can be either " or ' but it should be same.

echo "<li><a href=\"content.php?subj=" . urlencode($subject["id"]) . "\">{$subject["menu_name"]</a></li>";

developerahusain
developerahusain
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue May 28, 2013 10:04 pm
Location: India,Lucknow

Re: using single and double quotoes

Postby Strider64 » Mon Jun 10, 2013 11:18 am

Here's a working link:
Code: Select all
echo '<li><a href="content.php?subj=' . urlencode($subject["id"]) . '">'  . $subject["menu_name"] . '</a></li>';


In my opinion using single quotes is easier, but everyone has their own programming style.
Using single quotes - exact values
Using Double quotes - let's you get the values of variables but you have to do \" for double quotes for html tags.
User avatar
Strider64
New php-forum User
New php-forum User
 
Posts: 69
Joined: Sat Mar 23, 2013 8:24 am

Re: using single and double quotoes

Postby rashatanda » Mon Jun 10, 2013 1:59 pm

Thanks for the response. I did apply the working code you sent, even though, i did not any error, but my
variables are get displayed in the browser.

1. The link variables $subject["menu_name"] - is not returning anything in the browser. I could see the link, but it is blank. when i hover mouse over the blank link, i could see it is there but not displaying or not visible.

2. But, when i do use echo the variable name before the code you sent, i could see this link showing in the browser.

echo $subject["menu_name"]
echo '<li><a href="content.php?subj=' . urlencode($subject["id"]) . '">' . $subject["menu_name"] . '</a></li>';
rashatanda
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Jun 10, 2013 6:01 am

Re: using single and double quotoes

Postby rashatanda » Mon Jun 10, 2013 2:29 pm

Please check the code you sent to me again. I still see combination of single and double quotes. see my explanation below

echo '<li><a href="content.php?subj=' . urlencode($subject["id"]) . '">' . $subject["menu_name"] . '</a></li>';


- see the ff
1. "content.php ---> which is double quotes

2. ?subj=' --> single quotes

3. "'>' --> again single and double quotes
rashatanda
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Jun 10, 2013 6:01 am

Re: using single and double quotoes

Postby developerahusain » Mon Jun 10, 2013 8:42 pm

here is the working code rashatanda.I have tested on my localhost.You do try and let me know of the outcome.
echo "<li><a href=\"content.php?subj=" . urlencode($subject['id']) . "\">".$subject['menu_name']."</a></li>";

developerahusain
developerahusain
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue May 28, 2013 10:04 pm
Location: India,Lucknow

Re: using single and double quotoes

Postby rashatanda » Mon Jun 10, 2013 9:17 pm

Thanks for the prompt response. This is still not working for me. I do not have any error, but the link is just not showing. Below is the whole code. I have been excited learning php, this little issue have been very problematic. I wait for your response again. thanks.


<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php include("includes/header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<ul class="subjects">
<?php
$subject_array = get_all_subjects();
while ($subject = mysql_fetch_array($subject_array)) {
echo "<li><a href=\"content.php?subj=" . urlencode($subject['id']) . "\">" . $subject['menu_name'] . "</a></li>";

$page_array = get_pages_for_subject($subject["id"]);
echo "<ul class=\"pages\">";
while ($page = mysql_fetch_array($page_array)) {
echo "<li><a href=\"content.php?page=" . urlencode($page['id']) . "\">" . $page['menu_name'] . "</a></li>";
}
echo "</ul>";
}

?>
</ul>
</td>
<td id="page">
<h2>Content Area</h2>
</td>
</tr>
</table>
<?php require("includes/footer.php"); ?>
rashatanda
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Jun 10, 2013 6:01 am

Re: using single and double quotoes

Postby rashatanda » Tue Jun 11, 2013 6:09 am

am back again,

when i made the following changes <a href> to <href> , my browser started showing my variables, but no link.

echo "<li><href=\"content.php?subj=" . urlencode($subject['id']) . "\">" . $subject['menu_name'] . "</li>";
- this will display my variables $subject['menu_name'] in the browser

echo "<li><a href=\"content.php?subj=" . urlencode($subject['id']) . "\">" . $subject['menu_name'] ."</a></li>";

- this will not display my variables in the browser.

- could this be a browser problem that does not like <a href ????

- i tried both mozilla and ie i got the same results?
rashatanda
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Jun 10, 2013 6:01 am

Re: using single and double quotoes

Postby developerahusain » Tue Jun 11, 2013 8:21 am

here is my working code.You modify it as per your requirements
<?
$quer1=mysql_query("select distinct group_name,gid from cr_menu_inventor where gid='1' ");
while($resul=mysql_fetch_array($quer1))
{
echo "<table width='135' cellpadding='0' cellspacing='0'><tr valign='top'>
<td width='135' valign='top' style='color:#ffffff' bgcolor='#000000' class='top_link'><a href='?request=form&fid=60&action=cin_menu&subaction=".$resul['group_name']."&queue=queue_wait' target='_self' class='top_link1'>
<b><font color='#ffffff' >".$resul['group_name']."</a></b></td><td>";
if($_REQUEST['subaction']==$resul['group_name'])show_gid1($resul['gid'],$resul['group_name']);
echo "</td></tr></table>";
}
?>

developerahusain
developerahusain
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue May 28, 2013 10:04 pm
Location: India,Lucknow

Re: using single and double quotoes

Postby developerahusain » Tue Jun 11, 2013 8:45 am

Try the above code rashatanda.But i would suggest you to use my below code using braces. echoing result using quotes is probably a difficult deal. So one day i worked on the code and found an easy way to do it. Here is the code

<? $quer1=mysql_query("select distinct group_name,gid from cr_menu_inventor where gid='1' ");
while($resul=mysql_fetch_array($quer1))
{
?>
<li><a href="content.php?subj=<? echo urlencode($subject['id']); ?>"><?=$subject["menu_name"];?></a></li>

<? } ?>

This will help you allot. I hope this helps friend and rashatanda you asked this question
could this be a browser problem that does not like <a href ????. No because a href is not related to php. It is related to html,means it is there even in any of .html pages. And html has no browser related problems

developerahusain
developerahusain
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue May 28, 2013 10:04 pm
Location: India,Lucknow

Re: using single and double quotoes

Postby rashatanda » Tue Jun 11, 2013 1:58 pm

am newbies to php, your code confused me further. I really do not know where those other variables in your code is coming from? are they global variables and i just need to copy and paste them into my code?

Also, i see u using <? instead of <?php , my ide is not recognizing this and is confusing?
rashatanda
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Jun 10, 2013 6:01 am

Re: using single and double quotoes

Postby rashatanda » Tue Jun 11, 2013 7:56 pm

Hi dear, i got this solved. The problem was coming from my css. The color from the ccs was override the anchor. I changed the color from the css and my anchor are now showing. Thanks a lot for your help
rashatanda
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Jun 10, 2013 6:01 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron