Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #10766 > unrolled thread

problem with many buttons

Started byAvnesh Shakya <avnesh.nitk@gmail.com>
First post2013-09-15 23:25 -0700
Last post2013-09-16 15:41 +0200
Articles 4 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  problem with many buttons Avnesh Shakya <avnesh.nitk@gmail.com> - 2013-09-15 23:25 -0700
    Re: problem with many buttons Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-16 12:57 +0200
    Re: problem with many buttons Fiver <numeralfive@gmail.com> - 2013-09-16 13:32 +0200
      Re: problem with many buttons Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-16 15:41 +0200

#10766 — problem with many buttons

FromAvnesh Shakya <avnesh.nitk@gmail.com>
Date2013-09-15 23:25 -0700
Subjectproblem with many buttons
Message-ID<9e813751-629b-4768-beee-e061431da1d4@googlegroups.com>
hi,
   I have a problem, I have created lot of blogs in my site, and i put those as button, so when i click on button(e.i. blog name), then it should be redirect on other page like. Now I am on page like localhost/blog/blogName.php, here I have all blog buttons, after clicking on a particular button, it should go on localhost/blog/commentShow.php?id=blogName, here blogName is a name of blog that button contains.

I am doing in page localhost/blog/blogName.php
<?php
                    $blogIds = 0;
                    $sql = "SELECT * FROM user_blogs";
                    $result = mysqli_query($con, $sql);
                    while($row = mysqli_fetch_array($result))
                    {
                        echo "<ul class='ulBullet horLine'>";
                        echo "<li>".$row['description']."</li>";
                        $bgname = 'bgname'.$blogIds;
                        echo "<li><button id=$bgname onclick = return(blogId($this))>".$row['blogs_name']."</button></li>";
                        $next = "SELECT * FROM users WHERE user_id=$row[user_id]";
                        $result12 = mysqli_query($con, $next);
                        $row12 = mysqli_fetch_array($result12);
                        echo "<li style=''><button class=''>".$row12['usename']."</button></li>";
                        echo '</ul>';
                        $blogIds++;
                    }
                    ?>
in last, i added 
<?php
        echo "<script type='text/javascript'>function blogId($bgid) { top.location.href = './blogComment.php?id=$bgid'; };</script>";
        ?>

it is going on that page but not contaid this value...

please help me, what's wrong with me...

thanks and regards,
Avnesh Shakya

[toc] | [next] | [standalone]


#10769

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-09-16 12:57 +0200
Message-ID<81143277.NzZOkkXJ78@PointedEars.de>
In reply to#10766
Avnesh Shakya wrote:

>    I have a problem, I have created lot of blogs in my site, and i put
>    those as button, so when i click on button(e.i. blog name), then it
>    should be redirect on other page like. Now I am on page like
>    localhost/blog/blogName.php, here I have all blog buttons, after
>    clicking on a particular button, it should go on
>    localhost/blog/commentShow.php?id=blogName, here blogName is a name of
>    blog that button contains.
> 
> I am doing in page localhost/blog/blogName.php
> <?php
>                     $blogIds = 0;
>                     $sql = "SELECT * FROM user_blogs";
>                     $result = mysqli_query($con, $sql);
>                     while($row = mysqli_fetch_array($result))
>                     {
>                         echo "<ul class='ulBullet horLine'>";
>                         echo "<li>".$row['description']."</li>";
>                         $bgname = 'bgname'.$blogIds;
>                         echo "<li><button id=$bgname onclick =
>                         return(blogId($this))>".
$row['blogs_name']."</button></li>";
>                         $next = "SELECT * FROM users WHERE
>                         user_id=$row[user_id]"; $result12 =
>                         mysqli_query($con, $next); $row12 =
>                         mysqli_fetch_array($result12); echo "<li
>                         style=''><button
>                         class=''>".$row12['usename']."</button></li>";
>                         echo '</ul>'; $blogIds++;
>                     }
>                     ?>
> in last, i added
> <?php
>         echo "<script type='text/javascript'>function blogId($bgid) {
>         top.location.href = './blogComment.php?id=$bgid'; };</script>"; ?>
> 
> it is going on that page but not contaid this value...
> 
> please help me, what's wrong with me...

You are not thinking clearly, and you have not done your homework.

Steps you have before you, probably best in that order:

- Learn how to ask questions the smart way:

  <http://www.catb.org/~esr/faqs/smart-questions.html>

- Do not use Google Groups for posting to Usenet, it is broken
  and filled with spam.  Use instead, for example, one of the following:

  <https://en.wikipedia.org/wiki/SeaMonkey>
  <https://en.wikipedia.org/wiki/Mozilla_Thunderbird>
  <https://en.wikipedia.org/wiki/Kontact#Usenet_News_Client>

- Learn HTML [1] and learn how to write *Valid* HTML:
  
  <http://validator.w3.org/>
  <news:comp.infosystems.www.authoring.html>

- Learn *at least* the *basics* of PHP:

  <http://php.net/manual/>

- Get used to a consistent, easily readable and maintainable code style
  for each markup/programming language that you are using.  For example,
  with regard to PHP, you can use

  <http://pear.php.net/manual/en/standards.php> pp.

  as basis for your code style.

- Get a decent integrated development environment that makes all
  of this a lot easier:

  <http://projects.eclipse.org/projects/tools.pdt>

- Learn the difference between server-side and client-side code,
  and between static and generated content. [1]

- Only use “echo” for *generated* content:

  <http://php.net/manual/en/tutorial.firstpage.php>

- Learn to structure your code.  Use functions in order to DRY;
  templates to separate business logic, like database queries,
  from output:

  <https://en.wikipedia.org/wiki/Don%27t_repeat_yourself>
  <http://php.net/manual/en/language.functions.php>
  <http://php.net/include>
  <http://php.net/require>
  <http://php.net/require_once>
  <http://www.smarty.net/>

- Escape input to prevent invalid input and (SQL) code injection:

  <https://en.wikipedia.org/wiki/Code_injection>
  <http://php.net/mysqli_real_escape_string>
  <http://php.net/manual/en/mysqli.quickstart.prepared-statements.php>
  <http://php.net/manual/en/pdo.prepare.php>

- Escape output to prevent invalid output and cross-site scripting (XSS):

  <http://php.net/addslashes>
  <http://php.net/htmlspecialchars>
  <http://php.net/rawurlencode>
  <http://php.net/manual/en/security.php>
  <https://en.wikipedia.org/wiki/XSS>

- Learn object-oriented programming:

  <http://en.wikipedia.org/wiki/Object-oriented_programming>

  With regard to PHP:

  <http://php.net/manual/en/language.oop5.php>

- Learn J(ava)Script/ECMAScript and how to use the DOM APIs. [1]
  See also <news:comp.lang.javascript>

- Learn (My)SQL and how to process (My)SQL query results with PHP
  (in an efficient way):

  <https://en.wikipedia.org/wiki/SQL>
  <http://dev.mysql.com/manual/>
  <news:comp.databases.mysql>
  <http://php.net/manual/en/mysqli.quickstart.php>
  <http://php.net/manual/en/pdostatement.fetchall.php>

[1] <https://developer.mozilla.org/> pp.

YMMV.  HTH.


PointedEars
-- 
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
  -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>

[toc] | [prev] | [next] | [standalone]


#10771

FromFiver <numeralfive@gmail.com>
Date2013-09-16 13:32 +0200
Message-ID<l16q8i$qgl$1@dont-email.me>
In reply to#10766
On 2013-09-16 08:25, Avnesh Shakya wrote:
> <?php
> echo "<script type='text/javascript'>function blogId($bgid) {
>top.location.href = './blogComment.php?id=$bgid'; };</script>";
>         ?>
> 
> it is going on that page but not contaid this value...

echo "... $bgid ..." will try to interpolate the PHP variable "$bgid"
into the string. Depending on your settings and whether $bgid actually
exists, this will result in an error or something you didn't want.
JavaScript variables and function arguments are not usually prefixed
with a "$" sign. Try this instead (without the <?php ... ?> around it):

<script type="text/javascript">
function blogId(bgid) {
    top.location.href = './blogComment.php?id=' + bgid;
}
</script>


regards,
5er

[toc] | [prev] | [next] | [standalone]


#10774

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-09-16 15:41 +0200
Message-ID<2017243.GSzyx3rZ4e@PointedEars.de>
In reply to#10771
Fiver wrote:

> On 2013-09-16 08:25, Avnesh Shakya wrote:
>> <?php
>> echo "<script type='text/javascript'>function blogId($bgid) {
>>top.location.href = './blogComment.php?id=$bgid'; };</script>";
>>         ?>
>> 
>> it is going on that page but not contaid this value...
> 
> echo "... $bgid ..." will try to interpolate the PHP variable "$bgid"
> into the string. Depending on your settings and whether $bgid actually
> exists, this will result in an error or something you didn't want.
> JavaScript variables and function arguments are not usually prefixed
> with a "$" sign. Try this instead (without the <?php ... ?> around it):
> 
> <script type="text/javascript">
> function blogId(bgid) {
>     top.location.href = './blogComment.php?id=' + bgid;
> }
> </script>

I am afraid that this code is not going to work until someone with a minimum 
clue will be rewriting it.  For example,

| echo "<li><button id=$bgname onclick = return(blogId($this))>".
| $row['blogs_name']."</button></li>";

is not going to work already because “$this” will be expanded to "" while 
generating the notice “Undefined variable: this”.  It must be “this” 
instead, and the “onclick“ attribute value must be quoted; but to know that 
you have to have at least a basic understanding of HTML, and you have to 
know the difference between server-side and client-side code, and between 
PHP (used here server-side) and ECMAScript/JavaScript (used here client-
side).


PointedEars
-- 
When all you know is jQuery, every problem looks $(olvable).

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web