1

I am trying to make a link only have lowercase characters so the link actually work.

I'm not sure where to put the following:

$menus[$s]['title'] = strtolower($menus[$s]['title']);

$menus[$s]['title'] is the string I want to have lowercase characters.

<? 

    $sql_menus="SELECT * FROM lb_categories WHERE parent_id = '".$menu[$c]['id']."'";
    $res_menus=mysql_query($sql_menus)or die(mysql_error());
    while($row_menus = mysql_fetch_array($res_menus, MYSQL_ASSOC)) {
        $menus[] = $row_menus; 
    }
    for($s=0;$s<count($menus);$s++){ ?>
    <li><a href="<? echo $menus[$s]['title']?>.html"><? echo $menus[$s]['title'] ?></a></li>

<? }unset($menus); ?>
        </ul>
        </li>
benomatis
  • 5,536
  • 7
  • 36
  • 59
user50248
  • 113
  • 2
  • 10
  • 1
    `$menus` is not a string, it's an array. Use ` echo strtolower($menus[$s]['title']); ?>` – Daniel W. Oct 02 '14 at 12:47
  • At the top of your loop you could do `$menus[$s]['title'] = strtolower($menus[$s]['title']);`> – Cyclonecode Oct 02 '14 at 12:48
  • Obligatory: please [don't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). *They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation)*. See the [red box](http://uk.php.net/manual/en/function.mysql-connect.php)? Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). [This article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which. – Jay Blanchard Oct 02 '14 at 12:49

2 Answers2

5

Just use the strtolower() function where you echo the filename:

<li><a href="<? echo strtolower($menus[$s]['title']); ?>.html"><? echo $menus[$s]['title'] ?></a></li>
danmullen
  • 2,556
  • 3
  • 20
  • 28
0

Also you could use foreach instead for:

<?php foreach($menus as $menu): ?>
    <li><a href="<?php echo strtolower($menu['title']); ?>.html"><?php echo $menu['title']; ?></a></li>
<?php endforeach; ?>
Footniko
  • 2,682
  • 2
  • 27
  • 36