0

I have the following code but when $newstring echos out as
'.-ucwords(strtolower(-['First.Name']))-.-'-'.-ucwords(strtolower(-['Last.Name']))-.-.php

It should echo out the fields from the database noy just that code.

If someone could help please

$txtname = "'. ucwords(strtolower($row ['First.Name'])) . '-'. ucwords(strtolower($row ['Last.Name'])) . "; 
$newstring = str_replace(" ", "-", $txtname);
while($row = mysql_fetch_array($result))

  {

                           echo'



                                <div class="cat-post-desc">
                                    <h3><a href="' . $newstring . '.php">' . $row['First.Name'] . ' ' . $row['Last.Name'] . '</a></h3>

                                    <p></p>
                                </div>';
3
Contributors
9
Replies
19
Views
4 Years
Discussion Span
Last Post by mpc123
1

This line:

$txtname = "'. ucwords(strtolower($row ['First.Name'])) . '-'. ucwords(strtolower($row ['Last.Name'])) . "; 

should be:

$txtname = ucwords(strtolower($row['First.Name'])) . '-' . ucwords(strtolower($row['Last.Name'])); 
0
while($row = mysql_fetch_array($result))
{
    $txtname = ucwords(strtolower($row['First.Name'])) . '-' . ucwords(strtolower($row['Last.Name'])); 
    $newstring = str_replace(" ", "-", $txtname);

    echo'<div class="cat-post-desc"><h3>
        <a href="' . $newstring . '.php">' . $row['First.Name'] . ' ' . $row['Last.Name'] . '</a>
        </h3><p></p></div>';

} /** <-- You need to close your while loop

And include the $txtname & $new string in your loop

Edited by Squidge

0

$txtname = ucwords(strtolower($row ['First.Name'])) . ' '. ucwords(strtolower($row ['Last.Name']));
remove the replace function ...

Don't complicate your life ... :)

Edited by cmps

0

i need the replace also though?

I have now got it to work to echo out the fields
BUT the ucwords is not working with the code that Squidge provided

0

No according to php.net he is doing it correctly :O

$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.